with t as(
select 'mross' UID, '2345' Itemid union
select 'mross' UID, '2897' Itemid union
select 'mross' UID, '2678' Itemid union
select 'jford' UID, '3958' Itemid union
select 'jford' UID, '6898' Itemid union
select 'jford' UID, '7582' Itemid union
select 'jford' UID, '2278' Itemid union
select 'jford' UID, '3768' Itemid
),
t2 (Uid, Items) as
(
SELECT UID, STUFF( ( SELECT ','+ Itemid
FROM t a
WHERE b.UID = a.Uid order by itemid asc
FOR XML PATH('')),1 ,1, '') ItemId
FROM t b
GROUP BY Uid
)
select * from t2 inner join t3 on t2.Uid=t3.uid and t2.Items <>t3.items
select 'mross' UID, '2345' Itemid union
select 'mross' UID, '2897' Itemid union
select 'mross' UID, '2678' Itemid union
select 'jford' UID, '3958' Itemid union
select 'jford' UID, '6898' Itemid union
select 'jford' UID, '7582' Itemid union
select 'jford' UID, '2278' Itemid union
select 'jford' UID, '3768' Itemid
),
t2 (Uid, Items) as
(
SELECT UID, STUFF( ( SELECT ','+ Itemid
FROM t a
WHERE b.UID = a.Uid order by itemid asc
FOR XML PATH('')),1 ,1, '') ItemId
FROM t b
GROUP BY Uid
)
select * from t2 inner join t3 on t2.Uid=t3.uid and t2.Items <>t3.items