变量可以在 OLE DB 命令中定义吗? [英] Can Variable define in OLE DB Command?
问题描述
我定义了一个变量 Test,它是@[User::Test],字符串值为 "abc".
I had defined a variable Test which is @[User::Test] with string value "abc".
我的问题是我可以设置更新我的表的 sql 命令,其中我的列值 = 我的变量吗?
My question is can I set the sql command that update my table where my column value = my variable ?
示例.
update tableA set ValueB = '1pm' where ValueA = '" + @[User::Test] + "'
但这对我不起作用.如何解决?
But this is not working for me. How to solve it ?
推荐答案
你必须在 SQL 文本中使用问号并使用查询配置绑定变量(IIRC,它是 Parameter Mapping
标签).例如,我曾经做过这样的事情:
You have to use a question mark in the SQL text and bind the variable using the query configuration (IIRC, it was the Parameter Mapping
tab). For example, I used to do stuff like this:
-- declare vars
declare @table varchar(256);
declare @sql varchar(max);
-- get the table as a parameter
set @table = ?;
-- drop the table if it already exists
if (object_id(@table) is not null) begin;
set @sql = 'drop table '+@table+';';
exec(@sql);
end;
-- create the table
set @sql = '
create table '+@table+' (
IPID int,
...
_rn int
);
';
exec(@sql);
在这里,我在谷歌找到了一个截图:https:///www.simple-talk.com/iwritefor/articlefiles/1455-SsisVariables_Fig11-620x524.jpg
Here, I found a screenshot in Google: https://www.simple-talk.com/iwritefor/articlefiles/1455-SsisVariables_Fig11-620x524.jpg
这篇关于变量可以在 OLE DB 命令中定义吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!