0

Based on this link http://msdn.microsoft.com/en-us/library/ms170572.aspx, I successfully execute the SQL that I coded in the SQL file via the following code:

sqlcmd -S myServer\instanceName -i C:\myScript.sql

Now instead of executing a SELECT operation, I would like to have UPDATE operation. I'm wondering how to modify the above code so that it accept parameter and this parameter will be used in myScript.sql?

My sample UPDATE operation will be expected to be something like below:

UPDATE someColumn FROM someTable where tableID = @tableID;

So from the command, I will provide a tableID

2 Answers 2

1

There are few methods. Some of them are described here:

http://technet.microsoft.com/en-us/library/ms188714.aspx

sqlcmd -S myServer\instanceName -v tableID ="your_val" -i C:\myScript.sql


UPDATE someColumn FROM someTable where tableID = $(tableID);
Sign up to request clarification or add additional context in comments.

Comments

0

With -v parameter

  -v @tableID = 1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.