I have the following query which runs fine in Management Studio but when I put it in a SQLAgent job it fails saying
Error formatting query, probably invalid parameters (SQLState 42000 Error 22050)I have tried changing Quote characters but to no avail.
Does anybody have any idea why this would be happening?
Regards
Ron
declare @servername nvarchar(150)
set @servername = @@servername
declare @mysubject nvarchar(200)
set @mysubject = 'Toners adjusted out '+@servername+'.'
EXEC msdb.dbo.sp_send_dbmail @recipients='ron.grout@saywell.co.uk',
@subject = @mysubject,
@body = 'Toners were adjusted out. View attachment to see the details',
@query = 'use livedatabase;select trc_part, trc_job, trc_qty, trc_inits from livedatabase.dbo.Traces
where trc_part like "TONER%"
and CAST(trc_date as date) = CAST(getdate() as date)
and trc_typ = "O"',
@query_result_width = 600,
@attach_query_result_as_file = 1