Windows batch SQL query, database name includes percentage sign (%)

224 Views Asked by At

I've been using batch files with RazorSQL to query hosted Cache databases for certain data. I want to use the same process to collect the current backup times for Cache. The big difference is this data is stored in a system namespace that has a percent sign % in the name. The query looks like this:

Select * from %sys.task where name like '%Backup%'

This works fine from RazorSQL. But when I put it in a batch file, it fails because of the % sign. The batch file looks like this (which is very similar to other stuff I use successfully against regular database names):

"C:\Reporting\Casecount\RazorSQL\jre\bin\java" -jar "C:\Reporting\Casecount\RazorSQL\razorsql.jar" -export "Tst_Bkup" "Select * from %sys.task where name like '%Vision%'" csv NO

When you run this in a command window, you can see it parse out arguments, but the argument for the query comes out as this:

args[2]: Select * from Vision'

It basically skips from the first % to the 2nd %, and ignores everything in between. Against normal database names you'd see the query in this argument correctly. I've tried quotes, double quotes, brackets, exclamation points, etc, and can't get it to pass a % into the argument. I'm not a coder by trade, so I'm out of my depth here.

0

There are 0 best solutions below