﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2005 / SQL Server 2005 Security  / Cannot run query as job, but can run it as a query / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Tue, 21 May 2013 04:42:55 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Cannot run query as job, but can run it as a query</title><link>http://www.sqlservercentral.com/Forums/Topic1043889-359-1.aspx</link><description>silly possibility, make sure the user SQL Agent runs under has access to the database it queries.that was my problem, found it using the @append output option.</description><pubDate>Thu, 27 Dec 2012 13:48:41 GMT</pubDate><dc:creator>LAW1143</dc:creator></item><item><title>RE: Cannot run query as job, but can run it as a query</title><link>http://www.sqlservercentral.com/Forums/Topic1043889-359-1.aspx</link><description>Did you find a fix for this?  We are having the same issue.  Sometimes the job will work and other times (as in other days, same time) it won't.  Actually we have been having this on a number of our jobs.  We were able to get the same error when running manually as well (i.e. job fails, adjusted job time and still failed, manually run code in job and it fails, manually run code in job and it works) -- no rhyme or reason can be found yet.  Instead it returns:Msg 22050, Sev 16, State 1: Error formatting query, probably invalid parameters [SQLSTATE 42000]We are passing variables to the same sproc.</description><pubDate>Thu, 09 Feb 2012 07:57:17 GMT</pubDate><dc:creator>vconfused</dc:creator></item><item><title>RE: Cannot run query as job, but can run it as a query</title><link>http://www.sqlservercentral.com/Forums/Topic1043889-359-1.aspx</link><description>Add @append_query_error = 1 to the call to sp_send_dbmailThat way an email will be sent with the results of the attempt to run the query.</description><pubDate>Thu, 25 Aug 2011 07:39:23 GMT</pubDate><dc:creator>dpaproskijr</dc:creator></item><item><title>RE: Cannot run query as job, but can run it as a query</title><link>http://www.sqlservercentral.com/Forums/Topic1043889-359-1.aspx</link><description>Try assigning the values to variables, then using the variables when you call the proc.</description><pubDate>Thu, 06 Jan 2011 11:25:54 GMT</pubDate><dc:creator>GSquared</dc:creator></item><item><title>Cannot run query as job, but can run it as a query</title><link>http://www.sqlservercentral.com/Forums/Topic1043889-359-1.aspx</link><description>I'm having issues running a job in SMSS 2005. The queries themselves work fine on their own through SQL queries, but when inputted as a job it refuses to run. This is the general query[code="sql"]EXEC msdb.dbo.sp_send_dbmail @profile_name='ABC MAIL',	@recipients='xxx@abc.com',	@subject='Stats report for yesterday',	@body='See attachment',	@query='(SELECT * FROM XXX.dbo.fnReportAgentStatsYesterday()) UNION (SELECT * FROM XXX.dbo.fnReportAgentStatsYesterdaySummary()) ORDER BY abcName',	@attach_query_result_as_file=1,	@query_attachment_filename='AgentStatsYesterday.csv',	@query_result_separator='	',	@query_result_no_padding=1[/code]Here's a log of what happened:[quote]Job 'Agent Stats Report' : Step 1, 'Report' : Began Executing 2011-01-06 12:02:42Msg 22050, Sev 16, State 1: Error formatting query, probably invalid parameters [SQLSTATE 42000][/quote]Also the function: fnReportAgentStatsYesterdaySummary is linked to another server database and they do not share the same domain.I'm guessing it's something to do with SQL agent, according to other posts, but if anyone knows anything, that would be much appreciated.</description><pubDate>Thu, 06 Jan 2011 10:48:58 GMT</pubDate><dc:creator>sunpyo.hong</dc:creator></item></channel></rss>