Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Query runs in management studio but not in SQLAgent job

$
0
0

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


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>