Solved

sql store procdure issue, sql 2005

Posted on 2010-09-02
1
239 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
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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now