UPDATE:我发现有提出针对此问题的Microsoft连接的项目在这里
当使用FOR XML PATH和WITH XMLNAMESPACES声明一个默认命名空间时,我会在使用FOR XML的嵌套查询的任何顶级节点中复制命名空间decleration,我偶然发现了几个解决方案,但我并不完全相信.. .
这是一个完整的例子
/*
drop table t1
drop table t2
*/
create table t1 ( c1 int, c2 varchar(50))
create table t2 ( c1 int, c2 int, c3 varchar(50))
insert t1 values
(1, 'Mouse'),
(2, 'Chicken'),
(3, 'Snake');
insert t2 values
(1, 1, 'Front Right'),
(2, 1, 'Front Left'),
(3, 1, 'Back Right'),
(4, 1, 'Back Left'),
(5, 2, 'Right'),
(6, 2, 'Left')
;with XmlNamespaces( default 'uri:animal')
select
a.c2 …Run Code Online (Sandbox Code Playgroud)