根据条件将行插入表中
我有一个包,其中将 XML 数据插入记录集目标,并通过执行 SQL 任务从记录集目标插入数据库表
我的 XML 包含类似数据
<ROOT>
<row firstName="Joe" lastName="Blow" city="Seattle" state="WA" phone="555-666-7777"/>
<row firstName="Jane" lastName="Doe" city="Los Angeles" state="CA" phone="566-866-2345"/>
<row firstName="Robert" lastName="Smith" city="Washington" state="DC" phone="444-555-6666"/>
<row firstName="Mary" lastName="Contrary" city="Garden City" state="FL" phone="234-876-9374"/>
<row firstName="Thomas" lastName="Doubter" city="New Orleans" state="LA" phone="384-389-7342"/>
<row firstName="Barbara" lastName="Bologna" city="Chicago" state="IL" phone="483-483-8162"/>
</ROOT>
,并且我在包中采用了四个变量,所有变量都是字符串类型
firstname,lastname,city,state,phone
现在我的要求是我需要根据名字将此 XML 数据插入到我的目标表中。
如果我选择了 firstname= Robert
,则只有具有该名字的行才必须输入到我的目标表中。
我的执行 sql 任务包含
Result set Property--single row
connection type--OLEDB
connection--myconnection
sql statement--declare @firstName varchar(25)
select @firstName= ?
INSERT INTO people_xml (firstName, lastName,city,state,phone)
select firstName,lastName, city,state,phone from people_xml
where firstName=@firstName
Select Convert(varchar,Scope_Identity()) as SourceIDentity
参数映射选项卡
user::firstname
user::lastname
user::city
user::state
user::phone
结果集选项卡
result Name--0
variable Name--User::SourceID
当我运行包时,它会抛出如下错误
[执行 SQL 任务] 错误:执行查询“declare @firstName varchar(25) select @firstName= ...”失败并出现以下错误:“多步骤 OLE DB 操作产生错误。检查每个 OLE DB 状态值(如果有)。不 工作已完成。”。可能的失败原因:查询“ResultSet”出现问题 属性设置不正确、参数设置不正确或连接不正确 建立正确。
I have an package where am inserting XML data into record set destination and from record set destination to database table via Execute SQL
task
My XML contains data like
<ROOT>
<row firstName="Joe" lastName="Blow" city="Seattle" state="WA" phone="555-666-7777"/>
<row firstName="Jane" lastName="Doe" city="Los Angeles" state="CA" phone="566-866-2345"/>
<row firstName="Robert" lastName="Smith" city="Washington" state="DC" phone="444-555-6666"/>
<row firstName="Mary" lastName="Contrary" city="Garden City" state="FL" phone="234-876-9374"/>
<row firstName="Thomas" lastName="Doubter" city="New Orleans" state="LA" phone="384-389-7342"/>
<row firstName="Barbara" lastName="Bologna" city="Chicago" state="IL" phone="483-483-8162"/>
</ROOT>
and I have taken four variables in my package all of string type
firstname,lastname,city,state,phone
Now my requirement is I need to insert this XML data into my destination table based on first name..
If I have chosen firstname= Robert
, only row with that first name have to be entered into my destination table.
And my execute sql task contains
Result set Property--single row
connection type--OLEDB
connection--myconnection
sql statement--declare @firstName varchar(25)
select @firstName= ?
INSERT INTO people_xml (firstName, lastName,city,state,phone)
select firstName,lastName, city,state,phone from people_xml
where firstName=@firstName
Select Convert(varchar,Scope_Identity()) as SourceIDentity
Parameter mapping Tab
user::firstname
user::lastname
user::city
user::state
user::phone
result set Tab
result Name--0
variable Name--User::SourceID
When I am running the package it is throwing an error like
[Execute SQL Task] Error: Executing the query "declare @firstName varchar(25)
select @firstName= ..." failed with the following error: "Multiple-step OLE DB
operation generated errors. Check each OLE DB status value, if available. No
work was done.". Possible failure reasons: Problems with the query, "ResultSet"
property not set correctly, parameters not set correctly, or connection not
established correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个错误的问题是它非常普遍。就我个人而言,我遇到过两次此错误。有一次我通过匹配字段长度解决了这个问题。例如我在表中使用varchar(80),在插入时使用varchar(50)左右。我通过使用相同的类型和长度解决了这个问题。
第二次我遇到了真正的麻烦,但幸运的是,有一个人和我有同样的问题:我必须使用 regsvr32 注册 sqltaskconnections.dll。在互联网上搜索它,您会在那里找到指南。
如果我是你,我会尝试一下。正如我之前所说,这个错误非常普遍,除非有人真正明智地回答,否则我的猜测是您将不得不付出很多努力=-(
希望这会有所帮助!
The problem with this error is that is very generic. Personally I got this error twice. Once I solved it by matching the fields LENGTHS. For example, I used varchar(80) in the table and varchar(50) or so when inserting. I solved it by using the same type AND length.
The second time I was in real trouble but thankfully there was one guy that had the same problem than me: I had to register sqltaskconnections.dll using regsvr32. Search for it on the internet, you will find a guide there.
If I were you, I'd give it a try. As I said before, this error is really generic and unless someone really wise answers, my guess is that you'll have to struggle a lot =-(
Hope this helps!