Solved

sql store procdure issue, sql 2005

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Stored Proc - Rewrite 42 73
Need help in debugging a UDF results 7 55
SSMS Imprt data from Excel 7 28
MSSQL 2008 R2  Check to see if a Index/Key Exist 7 9
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…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 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