I have this query:
[select distinct pckwrk.ordnum AA,
pckwrk.prtnum BB,
pckwrk.pckqty CC,
pckwrk.appqty DD,
invdtl.rcvkey EE
from pckwrk,
invdtl
where pckwrk.ship_line_id = invdtl.ship_line_id
and pckwrk.wrkref = invdtl.wrkref
and pckwrk.prtnum = invdtl.prtnum
and pckwrk.wh_id = 'MFTZ'
and pckwrk.prt_client_id = 'HUS'
and invdtl.prt_client_id = 'HUS'
and pckwrk.ordnum = '85684780'
and pckwrk.prtnum = '1103329'
group by pckwrk.ordnum,
pckwrk.prtnum,
pckwrk.pckqty,
pckwrk.appqty,
invdtl.rcvkey]
It displays the following results:
aa bb cc dd ee
85684780 1103329 3 3 150900000164043
85684780 1103329 4 4 150900000164043
85684780 1103329 4 4 150900000164065
85684780 1103329 6 6 151200000170364
What can I do to consolidate rows 3 and 4 since they are identical and display column EE as follows:
aa bb cc dd ee
85684780 1103329 3 3 150900000164043
85684780 1103329 4 4 150900000164043,150900000164065
85684780 1103329 6 6 151200000170364
Thank you very much for your support!!
This is the code I am using that is giving me the error message: Status: 511-Database Error 511-Incorrect syntax near 'cast'.
[SELECT y.FF,
STUFF((SELECT ', ' + y.II
FROM (select distinct pckwrk.ordnum EE,
pckwrk.prtnum FF,
pckwrk.pckqty GG,
pckwrk.appqty HH,
invdtl.rcvkey II
from pckwrk,
invdtl
where pckwrk.ship_line_id = invdtl.ship_line_id
and pckwrk.wrkref = invdtl.wrkref
and pckwrk.prtnum = invdtl.prtnum
and pckwrk.wh_id = 'MFTZ'
and pckwrk.prt_client_id = 'HUS'
and invdtl.prt_client_id = 'HUS'
and pckwrk.ordnum = '85684780'
and pckwrk.prtnum = '1103329'
group by pckwrk.ordnum,
pckwrk.prtnum,
pckwrk.pckqty,
pckwrk.appqty,
invdtl.rcvkey) y
WHERE y.FF = x.FF FOR XML PATH(''), TYPE) .value('.[1]',' nvarchar(max)'), 1, 2, '')
FROM (select distinct pckwrk.ordnum EE,
pckwrk.prtnum FF,
pckwrk.pckqty GG,
pckwrk.appqty HH,
invdtl.rcvkey II
from pckwrk,
invdtl
where pckwrk.ship_line_id = invdtl.ship_line_id
and pckwrk.wrkref = invdtl.wrkref
and pckwrk.prtnum = invdtl.prtnum
and pckwrk.wh_id = 'MFTZ'
and pckwrk.prt_client_id = 'HUS'
and invdtl.prt_client_id = 'HUS'
and pckwrk.ordnum = '85684780'
and pckwrk.prtnum = '1103329'
group by pckwrk.ordnum,
pckwrk.prtnum,
pckwrk.pckqty,
pckwrk.appqty,
invdtl.rcvkey) x
GROUP BY y.FF]