使用批处理命令将参数值从批处理文件传递到sql文件 [英] Pass parameter value to sql file from batch file using batch command

查看:151
本文介绍了使用批处理命令将参数值从批处理文件传递到sql文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个sql文件update_qde.sql 其中包含以下代码

I have a sql file update_qde.sql which contains the following code

UPDATE profile_const
set parameter_value = '04_2015'
where profile_name = 'MIDAS_MTH_ALL_Panels'
and parameter_name = 'PERIODS_TO';
commit;

quit;

我还有另一个批处理文件test.bat

I have another batch file test.bat

我想使用批处理命令从批处理文件中将parameter_value作为变量传递.

I want to pass the parameter_value as a variable from a batch file using batch command.

您能告诉我任何方法吗?

Could you please show me any way to do this?

推荐答案

使用SQLCMD变量,因此将test.bat更改为调用SQLCMD而不是ISQL

Use SQLCMD variables, so change test.bat to call SQLCMD rather than ISQL

@echo off
sqlcmd -E -S myserver -i update_qde.sql -v PARM1=2015-01-01

更改SQL以使用$()表示法

Change the SQL to use the $() notation

UPDATE profile_const
SET parameter_value = '$(PARM1)'
WHERE profile_name = 'MIDAS_MTH_ALL_Panels'
AND parameter_name = 'PERIODS_TO';
COMMIT;

这篇关于使用批处理命令将参数值从批处理文件传递到sql文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆