SQLTeam.com | Weblogs | Forums

Variables passed from batch are not working in SQL Query


I have a batch file from which I am calling a .sql file.

Batch file:

SET Mod1=%1
SET CName=%2

SQLCMD -i "C:\Scripts\SQLFile.sql" -s "," -v Mod1="%Mod1%" CName="%CName%" >> "C:\Scripts\DSecurityLoad.xml" -h -1 -W

PRINT '$(Mod1)'
PRINT '$(CName)'

Select Users
from ASR_Load.dbo.TableName
'$(CName)' like ''''+'$(Mod1)'+''''

PRINT statement does print the variable values correctly. However, the values doesn't gets applied to the query.

Please help. Thanks.

It worked.

Where clause should be:
$(CName) like '$(Mod1)'