Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

How can you get SQLCMD, when executing a SQL script file, to just output any errors or warnings it encounters?

I essentially dont want information based messages to be output.

share|improve this question
    
Hmm, in another app we could redirect error output with 2> Err.txt, but it looks like SQLCMD does not split its output. –  Jon of All Trades Jun 28 '12 at 23:26

2 Answers 2

Found this on SQLServerCentral

sqlcmd -E -i"install.sql" -r1 2> install-err.log 1> install.log

http://www.sqlservercentral.com/Forums/Topic536968-146-1.aspx

share|improve this answer

The following will work:

sqlcmd -U user -P pass -S Server -Q "sp_who" -r1 1> test.log

The output from the query will be put into the log and nothing is printed on the screen.

In the case of an error, it will run like this:

 sqlcmd -U user -P pass -S Server -Q "sp_notreal" -r1 1> test.log

 Msg 2812, Level 16, State 62, Server XXXX, Line 1
 Could not find stored procure 'sp_notreal'

More details at the MSDN article on sqlcmd.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.