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 string that includes a sequence containing $ (MV).

When I run the script, I get the error β€œthe script variable MV is not defined.” Which I assume because it interprets the string $ (MV) as a variable instead of being part of a text string.

How can I write a dollar sign as an escape sequence? Is this possible in line?

+1
tsql powershell
Sep 06
source share
2 answers

You can use the backtick to avoid the $ sign in PowerShell:

`$ 
+3
Sep 06
source share

Is the script running with sqlcmd ? It will interpret $ (variablename) and try to expand it.

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

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

I assumed that you do not want the sqlcmd variable to be replaced. If you were just trying to get $ past Powershell, use the backlink (`$) as in the other sentence.

+7
Sep 06 '12 at 14:00
source share



All Articles