29 September,2012 by Jack Vamvas
A developer asked me to develop a template for executing SQLCMD with the output to the screen and output file. Normally it’s one or the other , but there is a workaround that allows SQLCMD to screen output and redirect output to file
Redirecting SQLCMD output to file is done with the –o switch. When using the –o switch , the output that normally would go to the screen , is redirected to the output file. On this occasion the developer wanted to both redirect the output to screen and the log file.
The purpose was to build in some interactivity with PAUSE , and make decisions on whether to continue based on the screen output.
The workaround to use the –o switch AND view the output on the screen is to use the the DOS TYPE command. The TYPE command displays the contents of a text file.
SQLCMD -E -S MyServer\MyInstance -i "mysqlscript.sql" -o output.log :: The next step outputs output.log to the screen echo The query output was: TYPE output.log
Powershell : SQLCMD and invoke-expression
SQL Server – Open SSMS without the splash screen graphic
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |