SQL脚本命令行参数 [英] SQL Script Command Line Arguments
问题描述
是否有一种方法可以获取将通过SQLCMD执行的脚本文件,以接受在SQLCMD调用中传递的语法。
Is there a way to get a script file that will be executing via SQLCMD to accept the parms passed in the SQLCMD call..
即
SQLCMD(假设连接正常。)-V1/25/2012-iScriptFile.sql
SQLCMD (assume the connection is OK..) -V "1/25/2012" -i "ScriptFile.sql"
ScriptFile.sql的结构会是什么样子?它会开始与任何其他程序相同吗?
What would the structure of ScriptFile.sql Look like? Would it start with the same as any other procedure..?
基本上我试图调用一个文本文件脚本作为SQL命令的参数。到目前为止我还没有找到任何MSDN文章在这一个。
Basically I'm trying to call a text file script with parameters as an SQL command. So far I haven't been able to find any MSDN articles on this one.
推荐答案
确定..如果任何人关心,它会像这样...
OK.. If anyone cares, it Goes Like This...
使用此变量的SQL脚本文件使用以下变量:
The SQL Script file which is using the variable uses the variable like so:
更新TableName Set ColumnValue = $(Param)
Update TableName Set ColumnValue=$(Param)
- 注意没有声明,参数的格式使用
$(Param)而不是@Param作为变量...
--Notice there's no declare, and the format of the parameter uses
$(Param) instead of @Param as a variable...
命令行看起来几乎相同。由于某些原因,传递的值需要在双引号内的单引号中,例如:
The Command line looks almost the same. For some reason, the passed value needs to be in single quotes within double quotes, like so:
SQLCMD -S ServerName -d DatabaseName -v Param = -iScriptFile.sql
SQLCMD -S ServerName -d DatabaseName -v Param="'Param'" -i"ScriptFile.sql"
在ScriptFile名称周围使用双引号,在参数中使用双引号。
Use just double quotes around the ScriptFile name, Single within Double for the Parameters.
这篇关于SQL脚本命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!