Pregunta

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

¿Fue útil?

Solución

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

Otros consejos

With -v parameter

  -v @tableID = 1
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top