Posts
1150
Comments
891
Trackbacks
1
T-SQL: sqlcmd nocount oddity

osql is a command-line program to interact with Sql Server, and is useful for launching scheduled batch files of Sql commands.

Well, it is deprecated, and sqlcmd is the new program to do the same thing.

I've come across one oddity: it is common to include print statements so that the output log file is more 'human readable', and easier to grep through, etc.

In weird combinations, calling:

print 'print text'

in a batch file will log out:

“0 rows affected.” 

This should never happen with a print statement, and you should be able to supress it with:

'set nocount on'

However, that command will only produce the desired behavior when followed with an explicit 'go' command.  'Set nocount off' takes effect immediately without an explicit 'go.'

posted on Friday, September 22, 2006 3:07 PM Print
Comments
Gravatar
# re: T-SQL: sqlcmd nocount oddity
Pete Singleton
11/4/2009 6:33 AM
I've just encountered this problem (using SQLCMD with MS-SQL 2005). Is there a solution other than using 'GO' as above?
Gravatar
# re: T-SQL: sqlcmd nocount oddity
jdn
11/4/2009 12:52 PM
Not that I am aware of.

Post Comment

Title *
Name *
Email
Url
Comment *  
Please add 2 and 5 and type the answer here: