INF: Using Return Codes with xp_cmdshell Stored ProcedureID: Q184039
|
This article describes the behavior that you will observe when you use return codes with the xp_cmdshell stored procedure on different versions of Microsoft SQL Server.
The "Microsoft SQL Server Transact-SQL Reference" includes an example of
the xp_cmdshell extended stored procedure and how to use return codes from
it in a batch to perform conditional execution. It is documented
incorrectly, however.
Using the following modified example, you can expect different behavior
Based on which version of Microsoft SQL Server you are using.
DECLARE @result int
EXEC @result = xp_cmdshell "dir *.exe"
/* The original result was evaluated against 1 */
IF (@result = 0)
PRINT 'Success'
ELSE
PRINT 'Failure'
Keywords : SSrvStProc SSrvTran_SQL
Version : WinNT:4.2x,6.0,6.5
Platform : winnt
Issue type : kbinfo
Last Reviewed: April 16, 1999