Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run exe file with parameter from SQL Server

Tags:

sql

sql-server

enter image description hereI have created a console application and now I want to execute this .exe file from SQL Server. Running this query only gets null output. Please help me.

    DECLARE @CMDSQL VARCHAR(1000), 
            @Reportname VARCHAR(100),
            @TerminalCode VARCHAR(10),
            @FinYear VARCHAR(10)  

    SET @Reportname =('05 - Import Load Delivery')  
    SET @FinYear='2017-18'  
    SET @TerminalCode='BOM'  
    SET @CMDSQL = '"D:\ExportToExcel.exe" ' + @Reportname + ' ' + @TerminalCode + ' ' + @FinYear  

    --print @CMDSQL  
    Exec master..xp_cmdshell @CMDSQL
like image 290
waseem ansari Avatar asked Oct 18 '22 12:10

waseem ansari


1 Answers

Try this:

SET @CMDSQL = 'CMD /S /C " "D:\ExportToExcel.exe"  "' + @ReportName + '" "' + @TerminalCode + '" "' + @FinYear + '" "'

It is important to quote the individual parameters as @DanGuzman suggested.

like image 154
Boulder Keith Avatar answered Oct 20 '22 22:10

Boulder Keith