SQL Server Xml命名空间查询问题
在xml变量@ResultData中有以下内容SQL Server Xml命名空间查询问题,xml,sql-server-2008,namespaces,xpath,Xml,Sql Server 2008,Namespaces,Xpath,在xml变量@ResultData中有以下内容 想法?建议?解决方案?知道了……当然,问了之后就知道了 ;WITH XMLNAMESPACES (N'http://schemas.microsoft.com/dynamics/2006/02/documents/EntityKey' as DYN) SELECT IDENTITY(int,1,1) as 'ID', c.value('(DYN:KeyData/DYN:
想法?建议?解决方案?知道了……当然,问了之后就知道了
;WITH XMLNAMESPACES (N'http://schemas.microsoft.com/dynamics/2006/02/documents/EntityKey' as DYN)
SELECT IDENTITY(int,1,1)
as 'ID',
c.value('(DYN:KeyData/DYN:KeyField/DYN:Value)[1]', 'VARCHAR(40)')
as 'JournalNum'
INTO #tmpBatches
FROM @ResultData.nodes('//EntityKey') t(c)
由于您只有一个名称空间,因此可以使用默认名称空间来避免在任何地方都使用前缀:
;WITH XMLNAMESPACES (DEFAULT N'http://schemas.microsoft.com/dynamics/2006/02/documents/EntityKey')
SELECT IDENTITY(int,1,1)
as 'ID', c.value('(<strike>DYN:</strike>KeyData/DYN:KeyField/DYN:Value)[1]', 'VARCHAR(40)')
as 'JournalNum'
INTO #tmpBatches
FROM @ResultData.nodes('//EntityKey') t(c)
此外,我还偶然发现了一些注意事项,它们是如何忽略所有名称空间的,因为存在多个名称空间,并且您知道不会发生冲突。
非常感谢您!!我终于在xpath查询中摆脱了这些讨厌的名称空间。
;WITH XMLNAMESPACES (N'http://schemas.microsoft.com/dynamics/2006/02/documents/EntityKey' as DYN)
SELECT IDENTITY(int,1,1)
as 'ID',
c.value('(DYN:KeyData/DYN:KeyField/DYN:Value)[1]', 'VARCHAR(40)')
as 'JournalNum'
INTO #tmpBatches
FROM @ResultData.nodes('//EntityKey') t(c)
;WITH XMLNAMESPACES (DEFAULT N'http://schemas.microsoft.com/dynamics/2006/02/documents/EntityKey')
SELECT IDENTITY(int,1,1)
as 'ID', c.value('(<strike>DYN:</strike>KeyData/DYN:KeyField/DYN:Value)[1]', 'VARCHAR(40)')
as 'JournalNum'
INTO #tmpBatches
FROM @ResultData.nodes('//EntityKey') t(c)