0

I have a server config script we call with SQLCMD that runs a lot of other scripts in a folder, using :R \\folder\path\script.sql. One of those scripts creates an Agent job that has a TSQL step that uses parameterized variables, i.e. '$(A-MSG)' and SQLCMD treats these like variable expansion as it executes the script and throws errors that they're not defined (which they wouldn't be, until that Agent job executes).

We can make it execute and create the job correctly if we run the sub-script directly, using sqlcmd -i \\folder\path\script.sql -x. Is there a similar way to disable variable expansion when running a server config script that executes sub-scripts with :R?

1 Answer 1

2

Maybe someone can suggest a better method as this seems a kludge but instead of :r, you could shell out to another SQLCMD session:

::sqlcmd -i \\folder\path\script.sql -x -I

Also added -I for QUOTED IDENTIFIERS ON to override the horrible default of OFF.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.