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
 Query Result in Mailil

Author  Topic 

gsavitha
Starting Member

3 Posts

Posted - 2011-01-31 : 11:11:21
Hi All,

I need to send the query result in mail.I Succeffuly configured the database mail setup and received the test mail.

But If i execute the below query :-

EXEC msdb.dbo.sp_send_dbmail
@recipients=sg@domainname.com',
@body='Message Body',
@subject ='Message Subject',
@profile_name ='test',@query ='select top 10 * from cst ',
@attach_query_result_as_file = 1,@query_attachment_filename ='Results.txt'


I got this error:-

Msg 22050, Level 16, State 1, Line 0
Error formatting query, probably invalid parameters
Msg 14661, Level 16, State 1, Procedure sp_send_dbmail, Line 504
Query execution failed: ?Msg 208, Level 16, State 1, Server REPORT-PC, Line 1
Invalid object name 'cst'.


I any idea wold be very helful.Thanks in advance..

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-01-31 : 11:30:56
Maybe it is helping to specify the tablename in this form:
databasename.dbo.cst

So it would look like
,@query ='select top 10 * from databasename.dbo.cst '

where databasename should be replaced by your correct databasename.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -