Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Result in mail

Status
Not open for further replies.

gsavitha

MIS
Jan 28, 2011
14
0
0
GB
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'.


Any idea would be very helful.Thanks in advance..
 
[!]Invalid object name 'cst'.[/!]

This implies that there is no table named cst in the current database.

[tt][blue]
@query ='select top 10 * from [!]databasename.dbo.[/!]cst '
[/blue][/tt]

I encourage you to add the database name and dbo (assuming that cst is owned by the dbo schema).

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top