Just Code‎ > ‎

SQLCMD - Pass in scripting variables to the script

posted Sep 7, 2011, 1:40 AM by Peter Henell   [ updated Sep 7, 2011, 2:05 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
Comments