Question

I have foo.sql as:

print 'foo=$(foo)'

Then I have in foo.cmd the following shell script:

sqlcmd -i foo.sql -v foo="c:\path"

Running foo.cmd prints:

foo=\path

how do I escape the "c:"? Is dos-shell eating it, or is it sqlcmd?

Was it helpful?

Solution 2

OK, my mistake. the above does work.

What i did wrong was doing: sqlcmd -i foo.sql -v foo='c:\path'

(single quote, since I tried to pass them as ' ' sql string) that won't work. it will chop the c:

OTHER TIPS

cmd's argument delimiters include the equal sign. I've seen in other cases (such as bjam.exe) that the entire parameter sequence has to be quoted to work properly.

Try this:

sqlcmd -i foo.sql -v "foo=c:\path"

If it still strips the "c:" portion, I'd focus on sqlcmd. I don't personally have it installed to test with. This is based solely on experience with similar situations.

Using another shell causes this.

I just had this when running sqlcmd via powershell. Switched to using cmd.exe and it worked fine

double quotes to escape the ":" and single quotes so that sql treated the variable value as a string. e.g.

sqlcmd -S . -d myDb -i .\test.sql -v pathToFile = "'D:\Temp\temp\My.csv'"

Escape the backslash,

sqlcmd -i foo.sql -v foo="c:\\path"

It's actually your shell eating the \

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top