|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, January 20, 2011 1:30 PM
Points: 2,
Visits: 8
|
|
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
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
Here's a log of what happened:
Job 'Agent Stats Report' : Step 1, 'Report' : Began Executing 2011-01-06 12:02:42
Msg 22050, Sev 16, State 1: Error formatting query, probably invalid parameters [SQLSTATE 42000]
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.
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: 2 days ago @ 1:45 PM
Points: 15,442,
Visits: 9,572
|
|
Try assigning the values to variables, then using the variables when you call the proc.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Thursday, May 02, 2013 7:58 AM
Points: 12,
Visits: 189
|
|
Add @append_query_error = 1 to the call to sp_send_dbmail
That way an email will be sent with the results of the attempt to run the query.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, July 16, 2012 2:56 PM
Points: 1,
Visits: 12
|
|
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.
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Tuesday, June 11, 2013 12:53 PM
Points: 80,
Visits: 252
|
|
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.
|
|
|
|