有选择
的值的问题create table #XMLTest
(ItemXML xml)
insert into #XMLTest (ItemXML) values (
'<MessageType xmlns="ss"> <Subject>sub</Subject> </MessageType>'
)
WITH XMLNAMESPACES('ss' as x)
SELECT
ItemXML.query('(/x:MessageType/Subject)')
FROM
#XMLTest
drop table #XMLTest
答案 0 :(得分:1)
您的子元素也位于名称空间
WITH XMLNAMESPACES('ss' as x)
SELECT
ItemXML.query('(/x:MessageType/x:Subject)')
FROM
#XMLTest
答案 1 :(得分:0)
这就是我的意思:
WITH XMLNAMESPACES('ss' as x)
SELECT
ItemXML.query('(/x:MessageType/x:Subject)').value('.','varchar(20)')
FROM
#XMLTest