My Blog List

hotinit.com. Powered by Blogger.

Search This Blog

xp_cmdshell

Monday, 8 August 2011

This a best method to invoke command prompt through a stored Procedure

Syntax

EXEC xp_cmdshell 'Command as parameter'

To execute a command and to return an output use this method



EXEC xp_cmdshell 'dir *.exe'

To execute a command and not to return an output use the following method
EXEC xp_cmdshell 'dir *.exe', NO_OUTPUT


Example:----
DECLARE @result int
EXEC @result = xp_cmdshell 'dir *.exe'
IF (@result = 0)
   PRINT 'Success'
ELSE
   PRINT 'Failure'


No comments:

Post a Comment

 

Blogger news

Blogroll

Most Reading

8.6/10