?
Solved

sql store procdure issue, sql 2005

Posted on 2010-09-02
1
Medium Priority
?
255 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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 Copy Database Wizard 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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

801 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