Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How can I capture SQLCMD return value?

Author  Topic 

leoc50
Yak Posting Veteran

54 Posts

Posted - 2012-03-22 : 14:27:38
I have this 'dynamic' built query [below], works fine BUT I need to evaluate whther SQLCMD fail or not.
How can I capture the return value?

xp_cmdshell 'sqlcmd /Q "select count(*) from [SqlServerName].dba_monitor.dbo.vr_bp_dbactivit;" -oI:\MSSQL.1\MSSQL\Job_Logs\dbstatus.txt'

Thanks!

- lec

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-03-22 : 15:31:24
My understanding is that you cannot capture the status/return code of the "shelled" command. Rather, you can only capture the return code of the xp_cmdshell itself; whis is 1 or 0.
Go to Top of Page

leoc50
Yak Posting Veteran

54 Posts

Posted - 2012-03-23 : 10:54:40
I gathered that much after many tests!

but solve my problem with a tmp table:

xp_cmdshell ''sqlcmd /Q "insert into ##tmpstatus select count(*) from ['+@servername+'].dba_monitor.dbo.vr_bp_dbactivity;" -oI:\MSSQL.1\MSSQL\Job_Logs\dbstatus.txt'

Thanks :)

- lec
Go to Top of Page
   

- Advertisement -