Task Scheduler sqlcmd with %date command no output and no error log
-
Monday, July 16, 2012 11:54 AM
Dear all,
I am a newbie, and i hope i got the right forum for sqlcmd in task scheduler. We are using Server 2008, SQL Server 2008 Express, and are using Windows Task Scheduler for scheduling an Excel output for research purposes. The following string works in command prompt with csv created, but no csv file when scheduled as an action in Task Scheduler.
sqlcmd -i "E:\ReportScript\scripttest.sql" -o "E:\Reports\scripttest%date:~-10,2%%date:~-7,2%%date:~-4,4%.csv" -W -s ","
There is no error code and there is no output file from Task Scheduler. I get the following in the history:
Task Scheduler successfully completed task "\Test Reporting" , instance "{4e52e7ab-7019-44e2-8479-827d28d17748}" , action "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\sqlcmd.EXE" with return code 1.
I am using the same login ID for the task scheduler as my command prompt. If i leave out the various %date parameters in the action, the task scheduler runs and gives an output file scripttest.csv without problems. How can i rephrase the %date such that task scheduler can accept?
All Replies
-
Monday, July 16, 2012 12:14 PM
Check the article task scheduler return error code 1.
Please post your query on SQL Server forum.
Thanks
- Proposed As Answer by Santosh BhandarkarMicrosoft Community Contributor, Moderator Monday, July 16, 2012 12:44 PM
- Marked As Answer by Jeff RenModerator Friday, July 20, 2012 2:05 AM
-
Monday, July 16, 2012 12:48 PMOk, i have posted the same question on the SQL Server forum. However, my stomach feels this is a peculiarity with Task Scheduler. I have tried the suggestion on your recommended article, but observed no difference? Thanks in any case!

