SQLCMD how to use drive and path in scripting variables

  • OK. I have run out of ideas..

    I am trying to place all the scripting variables in a file and have my sqlcmd like be populated at runtime witht he appropriate values. For example..

    :Setvar DistributionServerDataFolderName "N'e:\Data'"

    and then call...

    :!!sqlcmd -E -S db51 -d master -o scriptout1.txt -v SVDistributionServerDataFolderName =$(DistributionServerDataFolderName) -i InstallDistribution.sql

    :go

    :exit

    when it replaces the DistributionServerDataFolderName with N'e:\Data'

    it interpets the colon as a command and produces the error...

    Sqlcmd: ':\Data' ': Invalid argument. Enter '-?' for help.

    i have tried delimiting this every which way possible, but no success.

    what am i doing wrong? what can i change?

    Please help!

    thanks

  • It looks like the SQLCMD -v option is expecting the variable to be quoted.

    SQLCMD -v myVariable="myValue"

    To get the the variable quoted add an additional set of double quotes:

    :SETVAR myVariable """N'C:\temp'"""

    :!!ECHO $(myVariable)

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply