Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escape sequence for $ (dollar sign) in T-sql script

I am running a T-SQL script, called from a powershell script, that contains a text row which includes a sequence containing $(MV).

When I run the script I get the error "'MV' scripting variable not defined." which I assume is because it interpretates the $(MV) string as a variable instead of being a part of the text string.

How can I write the dollar sign as an escape sequence? Is that possible in a string?

like image 480
Ergodyne Avatar asked Sep 06 '25 03:09

Ergodyne


1 Answers

Are you executing the script with sqlcmd? It will interpret $(variablename) and try to expand it.

You can disable this using the -x command-line option.

Oh, if you're using Invoke-Sqlcmd you can use the -DisableVariables parameter.

I was assuming you didn't want to have the sqlcmd variable substitution done. If you were just trying to get the $ past Powershell, use the back-tick (`$) as in another suggestion.

like image 80
GilM Avatar answered Sep 07 '25 20:09

GilM