Reputation: 337
I am trying to sending a file through Database mail , when i execute the query below without @query option mail is triggered but when i include the @query option i get the error mentioned.
if @@rowcount >0
EXEC msdb.dbo.sp_send_dbmail @profile_name = ' Errormail',@recipients='[email protected];',
@subject = 'A new Record created in the SSORunError Log Table' ,
@body = 'A new Record created in the SSORunError Log Table' ,
@query = 'select * from ip',
@attach_query_result_as_file = 1,
@query_result_width = 4000,
@query_attachment_filename = 'Details.txt'
Error Message :
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 , Line 1
Invalid object name 'ip'.
Thanks in advance
Upvotes: 1
Views: 1233
Reputation: 8832
Try using fully qualified name for the table:
SELECT * FROM yourDatabase.yourSchemaName.ip
You can also set @execute_query_database
parameter of your call to sp_send_dbmail
to contain the name of your database (although I think that using fully qualified name should be enough).
Upvotes: 2