Task Scheduler sqlcmd with %date command no output and no error log

Answered 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