Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Problem with Percent Sign in Sqlcmd in Batch_F

Author  Topic 

marjan.sayyad
Starting Member

15 Posts

Posted - 2013-12-26 : 17:36:35
I am trying to run this command from a batch file:
psexec \\servername -E cmd.EXE /c "sqlcmd -S s01-techsql1 /E -d dbname -v entertext="'%anything%'" -i c:\myfolder\myscript.sql -o c:\mypath\output.sql"
myscript.sql is like this:
select * from table_name
where summary like $(entertext);

It works from command prompt, but it does not work from inside of batch file. I am pretty sure it is because of using persent sign with option v ( I mean this part: -v entertext="'%anything%'" ) . Can somebody tell me why???

Mp

cgraus
Starting Member

12 Posts

Posted - 2013-12-27 : 04:48:37
In a batch file you use a double percent sign ( so, %% ) to pass in a single % sign.

psexec \\servername -E cmd.EXE /c "sqlcmd -S s01-techsql1 /E -d dbname -v entertext="'%%anything%%'" -i c:\myfolder\myscript.sql -o c:\mypath\output.sql"
Go to Top of Page
   

- Advertisement -