基于这里的问题概括的方法不同:使用带的东西/ XML的路径(“”)
Concatenate many rows into a single text string?
我想放在一起的连接字符串唯一的值。我的代码是目前:
select rc.Routage
, COUNT(distinct rc.Event)
, STUFF((select ', ' + cast(rcA.Event as varchar)
from Receiving rcA
where rcA.supplier = 'user'
and rcA.DATETIME > '20170322'
and rc.Routage=rcA.Routage
for xml path(''))
, 1, 1, '')
from Receiving rc
where rc.supplier = 'user'
and rc.DATETIME > '20170322'
group by rc.Routage
order by COUNT(distinct rc.Event)desc
这给了我,我期望的输出,但我想/消除的东西重复值XML路径字段。
我已经试过了stuff/xml部分中的distinct
和group by
的各种组合,但无法正确拼合在一起。
为了澄清,对于COUNT(distinct rc.Event)
= 2,我希望从stuff子句中看到2个不同的事件。我怎样才能做到这一点?
尼斯。也感谢您的其他指针 - 它们已被考虑在内。多谢。 – User632716