SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SQLCMD how to use drive and path in scripting variables


SQLCMD how to use drive and path in scripting variables

Author
Message
ShellyP
ShellyP
Old Hand
Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)Old Hand (305 reputation)

Group: General Forum Members
Points: 305 Visits: 366
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
Todd Engen
Todd Engen
SSCommitted
SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)SSCommitted (1.5K reputation)

Group: General Forum Members
Points: 1523 Visits: 6336
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)


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search