我有以下查询,它通过SQL的XML函数返回这些结果:
它已成功按PO编号分组,但我试图让XML列表也按运营商分组......
所以带有运营商fedex的行只会显示123456 for alltrackingno,带有运营商ups的行会显示ups987653 for alltrackingno。
尝试了各种各样的加入变种而没有成功。
提前谢谢!
select ponumber,
case
when ca_type = 'FEX'
then 'fedex'
when ca_type = 'UPS'
then 'ups' else ''
end as carrier,
stuff((select ', ' + ltrim(rtrim(trackingno)) from box ee
where ltrim(rtrim(trackingno)) <> '' and ee.orderno=e.orderno
order by box for xml path('')), 1, 2, '') as alltrackingno
from box e right join carrier on e.shiplist = carrier.ca_code
right join cms on e.orderno = cms.orderno
where cms.custnum = 100 and ltrim(rtrim(trackingno)) <> ''
and emailedtracking = 0
group by e.orderno, ponumber, ca_type