Search code examples
sql-serverxp-cmdshell

How to NOT SELECT the OUTPUT value from a command shell script inside a stored procedure?


I have a stored procedure which is used by an SSRS report.

But I need to run this before I run the query:

sys.xp_cmdshell @sqlCmd;

The problem is that running this first returns the OUTPUT cell. This throws off the report because it's expecting a proper query and not just "OUTPUT"

How do I go about omitting this OUTPUT SELECT? I tried to add "NO_OUTPUT" but it still does not work:

SET @sqlCmd = '"C:\Program Files (x86)\ImageConverter\ImageConverter.exe", NO_OUTPUT';

Solution

  • It looks like your syntax for calling with the no_output clause may be the issue. Though the MSDN docs show that syntax in one of the examples, the MSDN listed syntax, as well as this TechNet article suggests it is passed as a literal 2nd parameter to the xp_cmdshell procedure without the quotes, i.e.:

    SET @sqlCmd = '"C:\Program Files (x86)\ImageConverter\ImageConverter.exe"'
    exec master..xp_cmdshell @sqlCmd, NO_OUTPUT;