Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 msdb.dbo.sp_send_dbmail

Author  Topic 

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2012-04-20 : 02:51:13
Im getting this error to send query result to email.
How to solve?

Error:Msg 14661, Level 16, State 1, Procedure sp_send_dbmail, Line 495
Query execution failed: ?Msg 208, Level 16, State 1, Server testing, Line 1
Invalid object name '#Table1'.

IF OBJECT_ID('tempdb..#Table1') IS NOT NULL
drop table #Table1
select distinct FirstName,Lastname
into #Table1
from #Table2

BEGIN
EXEC msdb.dbo.sp_send_dbmail
@recipients='test@yahoo.com',
@body='test',
@subject ='test',
@profile_name ='testing',
@query ='select * from #Table1',
@attach_query_result_as_file = 1 ;
END

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-20 : 14:56:30
why do you need temporary table? why cant you pass query directly to sp_send_dbmail?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -