0
insert into PendingEmails (Subject,Body,ToEmail,PendingEmailStatusID)
select REPLACE( select subject from dbo.EmailTemplates where ID  = 7 ), '[CallID]'), (select Body from dbo.EmailTemplates where ID  = 7) ,contact.Email  ,5 
FROM  inserted AS i inner join Calls on i.CallID = Calls.CallId inner join Contact on calls.ContactID = Contact.ContactID
where contact.Email is not null and  contact.Email <> ''

I want to replace '[CallID]' in the subject with a value. that syntax is not working. I also tried using a variable, wont work either.

What is the best way to do that?

3 Answers 3

3
insert into PendingEmails (Subject)
select REPLACE(subject, '[CallID]', @callid)
from dbo.EmailTemplates
where ID  = 7

I can't see where you are joining to the call table to get calls.callid, have you already stored it into a variable?

You can skip the variable if you have a subquery that will produce it (bracket the scalar subquery)

insert into PendingEmails (Subject)
select REPLACE(subject, '[CallID]', (select callid from calls where id=9))
from dbo.EmailTemplates
where ID = 7

Or JOIN it

insert into PendingEmails (Subject)
select REPLACE(e.subject, '[CallID]', c.callid)
from dbo.EmailTemplates e
join calls c on c.id=9
where e.ID = 7
Sign up to request clarification or add additional context in comments.

Comments

1

You have some parenthesis shenanigans:

insert into PendingEmails (Subject) 
select REPLACE(( select subject from dbo.EmailTemplates where ID = 7 ), '[CallID]' , calls.callid)

2 Comments

Thanks for the accept. However, I think Richard has the better answer. I'd go with that instead.
your right.. i first tried this and it works so I hit acceded, Now I tried the other one it's nicer... Thanks a lot.
1
INSERT INTO PendingEmails (Subject) 
SELECT REPLACE(subject, '[CallID]' , calls.callid)
    FROM dbo.EmailTemplates 
 WHERE ID = 7

1 Comment

where does calls.callid come from?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.