简体   繁体   中英

Email reports via SQL Server 2008 R2 Reporting Services

We have SQL Server Reporting Services running on SQL Server 2008 R2 and we've created some subscriptions to email to specific people. My question is: can I query a database and use an email address from the database to automatically email the report based on that email address in the database?

You can use Sql Server Agent if you trying to send data automatically Time base

and You can use this code with modified according to Your Requirnment

declare @id int
declare @name varchar(25)
declare @age int
declare @exp datetime
declare @msgbody varchar(100)

declare @add varchar(max)
declare cursername cursor

for 

select id,name,age, convert(varchar(10),exprire,103)as exprire from Tablename 

open cursername
fetch next from cursername into  @id ,@name,@age,@exp



while @@FETCH_STATUS = 0

begin
fetch next from cursername
into @id ,@name,@age,@exp

set @msgbody = ''+ CAST(@id as varchar(20))+ '    '+ @name +'    '+  CAST(@age as varchar(20))  +'    '+ CONVERT(varchar(20),@exp,103) +''
set @add = @add + @msgbody



print ''+ CAST(@id as varchar(20)) + @name +  CAST(@age as varchar(20))  + CONVERT(varchar(20),@exp,103) +''
end 


use msdb
EXEC sp_send_dbmail
@profile_name='dv', 
@recipients='Emailreciever@yahoo.com', 
@subject='Send data specific',
@body=   @add

close cursername
deallocate cursername

I hope it is useful to Your

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM