SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
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
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

marjan.sayyad
Starting Member

USA
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???

Mp

cgraus
Starting Member

Australia
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  
 New 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.05 seconds. Powered By: Snitz Forums 2000