SQLCMD - Pass in scripting variables to the script

Post date: Sep 7, 2011 8:40:22 AM

the "v" switch allow you to pass custom scripting parameters. ReplicationTarget is a name i chose by myself

sqlcmd -E -S localhost -d ReplicationSourceDB -i test.sql -v ReplicationTarget="CustomerDB"

test.sql:

declare @replicationTarget NVARCHAR(2000) = '$(ReplicationTarget)'print @replicationTarget

Output:

CustomerDB