8
如何構建XML並將其作爲參數傳遞給MS SQL 2005服務器上的存儲過程?你怎麼將INSERT
XML轉換成表格?存儲過程:將XML作爲參數傳遞並插入(鍵/值對)
的數據是鍵/值對的形式:
[
0: [key, value],
1: [key, value],
2: [key, value]
]
如何構建XML並將其作爲參數傳遞給MS SQL 2005服務器上的存儲過程?你怎麼將INSERT
XML轉換成表格?存儲過程:將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
真的很好的答案。謝謝! – roosteronacid 2010-08-25 08:31:16