大佬教程收集整理的这篇文章主要介绍了在临时表中打开XML插入-SQL 2005,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
DECLARE @test XML
SET @test = '<Products><ProductID>1</ProductID><ProductID>2</ProductID></Products>'
DECLARE @temp table(ProductID NVARCHAR(10))
DECLARE @docHandlE int
EXEC sp_xml_preparedocument @docHandle OUTPUT, @doc
INSERT INTO @Temp(ProductID)
SELECT t.value('./ProductID[1]','NVARCHAR(10)') AS 'ProductID'
FROM OPENXML(@docHandle, '//Products', 1) t
EXEC sp_xml_removedocument @docHandle
我有一个存储过程,正在传递一个简单的XML:
'<Products><ProductId>1</ProductId><ProductId>2</ProductId></Products>'
我在SQL中有一个@temp表,其中有一个ProductId列:
DECLARE @temp table (
ProductId NVARCHAR(10)
)
我需要编写一条插入语句,该语句将遍历XML中的ProductId(可以是无限的),并继续插入(在@temp表中),直到XML不再剩余ProductId节点为止。
涉及游标的解决方案是不可行的!
以下是我尝试执行的代码:
Declare @test XML
SET @test = '<Products><ProductId>1</ProductId><ProductId>2</ProductId></Products>'
DECLARE @temp table(
ProductId NVARCHAR(10)
)
INSERT INTO @Temp(ProductId)
SELECT tab.col.value('./ProductId[1]','NVARCHAR(10)') AS 'ProductId'
FROM @test
CROSS APPLY
xml_data.nodes('//Products') AS tab(col)
我不断收到错误:
@H_704_3@must declare the table variable "@test".
以上是大佬教程为你收集整理的在临时表中打开XML插入-SQL 2005全部内容,希望文章能够帮你解决在临时表中打开XML插入-SQL 2005所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。