January 8, 2014 at 8:54 am
Hello.
We are running SQL Server 2008 on a Windows Server 2008 R2 SP1 box. I have a SQL query that reads through the database and writes output to a flat file.
When I run the query directly in SQL Server Management Studio and choose Query --> Results to File, the query runs in a little less than 2 minutes.
However, when I run the same query, writing to the same output file, but run the query in a batch job through Task Scheduler, it takes over 3 hours to run!
The command in the batch file is:
sqlcmd -s <SQL Server instance> -i <the name of the file that is the SQL query itself> -o <the name of the output file> -d <the name of the database> -h -1 -W -r 0
Why does it take so much longer to run through the Task Scheduler? Are there parameters that I am missing and should be setting to increase the priority of the job or should I be attacking this in some other way? Any suggestions would be greatly appreciated.
Thanks!
January 8, 2014 at 4:03 pm
My guess would be that somehow task schedule is using a batch size of 1 row (or some very small number of rows). See if you can change the batch size.
SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply