Pass parameters in SQLCMD

  • is it possible to pass parameters into sqlcmd. For instance user A wants to pass inthe location of the folder where his files are stored and in turn replace the location in the command below

    the sqlcmd that is used is as following:

    :r "\\user\c$\folder\xyz.sql"

    Noli Timere
  • Yes, you can use variables with sqlcmd, see Books Online (http://msdn.microsoft.com/en-us/library/ms188714.aspx) for more details.

    E.g.:

    In your script change the definition to:

    :r $(scriptfile)

    Assign the variable at execution:

    sqlcmd.exe -v scriptfile="\\user\c$\folder\xyz.sql"

    ML

    ---
    Matija Lah, SQL Server MVP
    http://milambda.blogspot.com

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

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