質問

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

役に立ちましたか?

解決

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);

他のヒント

With -v parameter

  -v @tableID = 1
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top