English 中文(简体)
Send the table data to an email using DB Send mail in SQL Server
原标题:

I am trying to send the table data which comprises of 2 columns Status and Count through email. And I need to achieve this from stored procedure with DB send mail. I wrote the below code, but the variable @msgsource which is for body of the mail is returning NULL value. Can someone look into this?

Declare @msgsource varchar(max)

If object_id( Tempdb..#Temp1 ) is not null drop table #Temp1

-- To get the Submittable_Ready records before job run
Select  Submittable-Ready  as Status, Count(*) as [Count] Into #Temp1
from smt_837_Submitted_Housecalls_Claims clm(nolock)  
where clm.Edi_config_ref = 1 and 
clm.[Status] like  Submitted 
and cast (refresh_date as date) = cast(getdate() as date)

If object_id( Tempdb..#Temp2 ) is not null drop table #Temp2

-- To get the Submittable_Ready records after job run
Select  Submittable-Ready  as Status, Count(*) as [Count] Into #Temp2
from smt_837_Submitted_Housecalls_Claims clm(nolock)  
where clm.Edi_config_ref = 1 and 
clm.[Status] like  Submittable-Ready 
and cast (refresh_date as date) = cast(getdate() as date)



SET @msgsource =@msgsource+ <br> Submittable Ready records before job run,<br>  
<table border ="1"> <tr><p style="color:#FFFFFF">  
 <td bgColor="#808080" >Status</td>   
 <td bgColor="#808080" >Count</td>     </tr>  <p style="color:#00000">   
select @msgsource
SET @msgsource=@msgsource  
+Cast((SELECT [Status] as td,   ,cast([Count] as varchar(10)) as td,    
-- ,(Case when ([Comments] like  %Duplicate%  or [Comments] like  %Test% ) then Cast( <font 
color="Red"> +[Comments]+ </font>  as XML) else [Comments] end) as td,    
from #temp1  FOR XML PATH( tr ), ELEMENTS) as varchar(max))  
 + </table>   

 --select @msgsource

 SET @msgsource =@msgsource+ <br> Submittable Ready records after job run,<br>  
 <table border ="1"> <tr><p style="color:#FFFFFF">  
 <td bgColor="#808080" >Status</td>   
 <td bgColor="#808080" >Count</td>     </tr>  <p style="color:#00000">   
 
 SET @msgsource=@msgsource  
 +Cast((SELECT [Status] as td,   ,cast([Count] as varchar(10)) as td,    
 -- ,(Case when ([Comments] like  %Duplicate%  or [Comments] like  %Test% ) then Cast( <font 
 color="Red"> +[Comments]+ </font>  as XML) else [Comments] end) as td,    
 from #temp2  FOR XML PATH( tr ), ELEMENTS) as varchar(max))  
  + </table>   
 
  Select @msgsource
问题回答

暂无回答




相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签