Search code examples
batch-filesqlcmd

concatenation in windows batch file


Here is the code in my batch file

set startdate="9/1/2011"
set enddate="10/31/2011"

sqlcmd -Q "exec mysp '%startdate%', '%enddate%'"

I want to execute the command in SQL Server:

exec mysp '9/1/2011', '10/31/2011'

Solution

  • Well, you haven't exactly told us what's going wrong but I'm guessing the double quotes arond the dates are being included in the command, as per:

    C:\Users\Pax> set startdate="9/1/2011"
    
    C:\Users\Pax> echo %startdate%
    "9/1/2011"
    
    C:\Users\Pax> set startdate=9/1/2011
    
    C:\Users\Pax> echo %startdate%
    9/1/2011
    

    Try removing them.