如何在 SQL for XML 查询 (MSSQL) 中添加名称空间标头

问题描述 投票:0回答:0

我有以下问题

select distinct
t.Code as Prime,
t.nom as Alfa,
t.Nom as Name,
t.Adresse as Street,
t.CP as ZipCode,
t.Localite as City, 
case t.CodePays when null then 'BE' when '' then 'BE' else t.CodePays end as Country,
Case t.CodeLangue when 'NL' then 1 when 'FR' then 2 when 'EN' then 3 when 'DE' then 4 else 1 end as Language,
'EUR' as CurrencyCode,
Case t.Tva when '' then 0 else 1 end as VATCode,
Case t.Tva when '' then 0 else 1 end as VATStatus,
t.Tva as VATNumber,
case t.CodePays when null then 'BE' when '' then 'BE' else t.CodePays end as CountryVATNumber,
0 as Status /* 0=pas importé*/ 
from tiers t inner join tiersexport te on t.code=te.code where t.CodeTypeTiers in(1,3)
order by t.Code FOR XML PATH('Customer'), ROOT('Customers');

谁为我生成了合适的 XML

...

我需要有

...

你能告诉我怎么做吗?

我试过了

WITH XMLNAMESPACES( 'http://www.w3.org/2001/XMLSchema' as xsd,'http://www.w3.org/2001/XMLSchema-instance' as xsi)
select distinct
t.Code as Prime,
t.nom as Alfa,
t.Nom as Name,
t.Adresse as Street,
t.CP as ZipCode,
t.Localite as City, 
case t.CodePays when null then 'BE' when '' then 'BE' else t.CodePays end as Country,
Case t.CodeLangue when 'NL' then 1 when 'FR' then 2 when 'EN' then 3 when 'DE' then 4 else 1 end as Language,
'EUR' as CurrencyCode,
Case t.Tva when '' then 0 else 1 end as VATCode,
Case t.Tva when '' then 0 else 1 end as VATStatus,
t.Tva as VATNumber,
case t.CodePays when null then 'BE' when '' then 'BE' else t.CodePays end as CountryVATNumber,
0 as Status /* 0=pas importé*/ 
from tiers t inner join tiersexport te on t.code=te.code where t.CodeTypeTiers in(1,3)
order by t.Code FOR XML PATH('Customer'), ROOT('Customers');

但后来我收到了 ...

sql-server xml-namespaces for-xml-path
© www.soinside.com 2019 - 2024. All rights reserved.