gpt4 book ai didi

c# - 存储过程 : pass XML as an argument and INSERT (key/value pairs)

转载 作者:数据小太阳 更新时间:2023-10-29 01:44:21 25 4
gpt4 key购买 nike

您将如何构建 XML 并将其作为参数传递给 MS SQL 2005 服务器上的存储过程?您将如何INSERT XML 到表中?

数据是键/值对的形式:

[
0: [key, value],
1: [key, value],
2: [key, value]
]

最佳答案

这是一个例子:

/* Create the stored procedure */
create procedure ParseXML (@InputXML xml)
as
begin
declare @MyTable table (
id int,
value int
)

insert into @MyTable
(id, value)
select Row.id.value('@id','int'), Row.id.value('@value','int')
from @InputXML.nodes('/Rows/Row') as Row(id)

select id, value
from @MyTable
end
go

/* Create the XML Parameter */
declare @XMLParam xml
set @XMLParam = '<Rows>
<Row id="1" value="100" />
<Row id="2" value="200" />
<Row id="3" value="300" />
</Rows>'

/* Call the stored procedure with the XML Parameter */
exec ParseXML @InputXML = @XMLParam

/* Clean up - Drop the procedure */
drop procedure ParseXML
go

关于c# - 存储过程 : pass XML as an argument and INSERT (key/value pairs),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3557882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com