Solved

sql store procdure issue, sql 2005

Posted on 2010-09-02
1
251 Views
Last Modified: 2012-08-13
hi All i have written a query where it sends an email it sending email but for some reaso in body it is showing only Dear after that everything is miising in tablehtml.

can some one take a look at my query and tell me what mistake i am doing in my @tablehtml.

use [stagingdatabase]
create table #emailsent(
customerid nvarchar(50) not null,
customername nvarchar(255),
customeremail nvarchar(255),
storeid nvarchar(3),
[storeaddress] nvarchar(255),
storecity nvarchar(50),
storeprovince nvarchar(3),
storephonenumber nvarchar(10),
storeZip nvarchar(10),
Storeemail nvarchar(255),
Storemanager nvarchar(255),
storeemailnotes nvarchar(max),
emailsend bit)

insert into #emailsent (customerid,customername,customeremail,storeid)
select customerid,customername,email,storeid from dbo.customeremails where emailsend is null group by customerid,customername,email,storeid

update #emailsent set storeid = st.storeid,[storeaddress] = st.address,storecity = st.city,storeprovince = st.province,storezip = st.zip,storephonenumber = st.phonenumber,storeemail = st.storeemail,storemanager = st.manager,storeemailnotes = st.emailnotes
from #emailsent es inner join dbo.iqmlocations st on es.storeid = st.storeid

declare @customerid nvarchar(10),
@customeremail nvarchar(255),@storeemail nvarchar(255)

declare cusid cursor FAST_FORWARD FOR
select customerid,customeremail,storeemail from #emailsent where emailsend is null

DECLARE @tableHTML  NVARCHAR(MAX);

OPEN cusid
FETCH NEXT FROM cusid
INTO @customerid,@customeremail,@storeemail

WHILE @@FETCH_STATUS = 0
BEGIN

SET @tableHTML =
    N'<b>Dear ' select customername from #emailsent where customerid = @customerid + '</b></br></br>' +
      N'Thank you for shopping with us</br> If you have any problems please do contact us</br>' +
      N'Thank you </br>'+
      N'Manager ' Select storemanager from #emailsent where customerid = @customerid + '</br>' +
      N'<b> ' Select storeaddress from #emailsent where customerid = @customerid + '</br>'
      --N '<b>'select storeaddress from #emailsent where customerid = @customerid + '</b></br>'
       ;

EXEC msdb.dbo.sp_send_dbmail
       @recipients=@customeremail,
      -- @replyto_address = @storeemail,
     @subject = 'Thank You' ,
     @body = @tableHTML,
     @body_format = 'HTML'
--select * from #emailsent

update dbo.#emailsent set emailsend = 1 from dbo.#emailsent where customerid = @customerid

FETCH NEXT FROM cusid
     INTO @customerid,@customeremail,@storeemail
END

CLOSE cusid
DEALLOCATE cusid

update dbo.customeremails set emailsend = '1' --from dbo.neccredits n inner join #nec1 ne on n.docnum = ne.docnum

select * from #emailsent
drop table #emailsent
0
Comment
Question by:romeiovasu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 22

Accepted Solution

by:
pivar earned 500 total points
ID: 33590424
Hi,

Instead of

SET @tableHTML = ...

try


SELECT @tableHTML = N'<b>Dear ' + ISNULL(customername, '') + '</b></br></br>' +
      N'Thank you for shopping with us</br> If you have any problems please do contact us</br>' +
      N'Thank you </br>'+
      N'Manager '+ ISNULL(storemanager , '') +  '</br>' +
      N'<b> ' + ISNULL(storeaddress , '') + '</br>'
</br>'
FROM #emailsent where customerid = @customerid;

/peter
0

Featured Post

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question