SQL Server email function invalid syntax I have this sp_send_dbmail script. The error log shows "invalid syntax error".

EXEC msdb.dbo.sp_send_dbmail
    @profile_name = 'PROFILE_NAME',
    @recipients = 'oops@wrongagain.com',
    @subject = ' Search for empty ID result ',
    @query = ' select * from [dbo].[TT_INCI] tt where tt.ts_caseid =''(Auto)'' ',
    @attach_query_result_as_file = 0


Please help
You need to speficy the database where the table is:

EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'DBProfile',
@recipients = 'jupiter@love.com',
@subject = ' Search for empty ID result ',
@query = ' select * from [SomeDatabase].[dbo].[TT_INCI] tt where tt.ts_caseid =''(Auto)'' ',
@attach_query_result_as_file = 0


The error message is a bit misleading.