views:

23

answers:

2

hi

i have a simple powershell script, like this

sqlcmd -S. -E -Q 'select ''$(x)''' -v x="c:a"

but i always got the error message

Sqlcmd: ':a': Invalid argument. Enter '-?' for help.

i figured out that it is the ":" in the argument caused the problem, but i do not know how to escape it.

thanks, David

A: 

The backquote character is the escape code in PowerShell. So write `: ....

oops... That won't work for the colon character. Use %3A instead.

Warren
i just tried that. it does not seem to work for me :(
davidshen84
and it will display '%3a' exactly for me? no, i want the sql script display 'c:a' for me.
davidshen84
i found out it is not a sqlcmd issue, it is the powershell did something with the ":" and did not pass it to sqlcmd. i executed the script in cmd.exe, and it works fine.
davidshen84
A: 

sorry that i have to answer to my own question again.

the only way to solve this problem is to use '+' to concatenate the two string, and the ':' will be reserved.

e.g. $a="abc"+":123"

davidshen84