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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Problem with Percent Sign in Sqlcmd in Batch_F
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

15 Posts

Posted - 12/26/2013 :  17:36:35  Show Profile  Reply with Quote
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???


Starting Member

12 Posts

Posted - 12/27/2013 :  04:48:37  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000