Sqlserver-dba.com

Subscribe

SQLServer-DBA.com Links

Subscribe to newsletter

Dba_db2_button

Powered by TypePad
SQL Server - SQLCMD with screen output and output file

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

 Related Posts

Powershell : SQLCMD and invoke-expression

SQL Server DBA Tools

SQL Server – Open SSMS without the splash screen graphic


Author: Jack Vamvas (http://www.sqlserver-dba.com)

******** *******

Enjoy this post? Enter your email address for updates on new posts:

Delivered by FeedBurner

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

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.

Working...

Post a comment


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer