Sorgu sonucu gelen düşey listeyi virgüller ile birleştirerek yatay hale getirmek.
SELECT A.COMPONENT
,STUFF( (SELECT ‘, ‘ + SUBSTRING(B.MATERIAL,LEN(B.MATERIAL)-6,7)
from IASBOMITEM B WITH (NOLOCK)
WHERE B.CLIENT=’00’ AND B.COMPANY=’01’ AND B.COMPONENT=A.COMPONENT
AND B.MATERIAL LIKE ‘%D’ FOR XML PATH(”)),1,1,”) AS MATERIALS
FROM IASBOMITEM A WITH (NOLOCK),IASMATBASIC C WITH (NOLOCK)
WHERE A.CLIENT=’00’ AND A.COMPANY=’01’ AND A.COMPONENT=C.MATERIAL
AND C.CLIENT=A.CLIENT AND C.COMPANY=A.COMPANY AND C.MATGRP LIKE ‘C-___’ AND C.ISDELETE=0
GROUP BY A.COMPONENT
ORDER BY A.COMPONENT
COMPONENT MATERIALS ------------------------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 806860 NULL D1028657 DPDNAHD, DPDNAHD D1028657K NULL D1028657S NULL D1059 NULL D140MM2X10S LILYAHD, LRYALHD D1446 LB178ZD D2266 LMS2GZD, LF51GZD, LMS2GZD D2565 LF82MZD, LF82MZD D267 LL261ZD, LL61ZQD, LM85SZD, LM87MZD, LMS84ZD, LMS94ZD, LU884ZD, LL261ZD, LM85SZD, LM87MZD, LMS84ZD, LMS94ZD D267-2 NULL D2837 LB175ZD D2837S LB175ZD D4035 DJ17ZAD D6236 DJP17HD D727907 F16MD D, LF80MZD, LF80MZD D728117 DLLADHD, FBASIHD, DLLADHD, FBASIHD D728135 LU0A4HD, LG18UHD, LB112HD, DP354HD, FBASIHD, LB112HD, FBBASHD D728135SS LU164HD, LB13UHD, LB13UHD D7849/S8 LTV20HD, DP492KD, DB392KD, DD392KD D806860 LP530HD, LTA16HD, LP530HD, LTS15HD, LU115HD, LTA16HD D806860/01 NULL D806860/02 LU118HD D80MM1X40S LP0A1HD D80MM2X10S LSKA1HD, DVICTHD, LL115HD, LP0A1HD D8300 LG11SHD D830-0015 LP120HD DG11780089 LBA24HD F001EL0707044CL FBBASKD FLBSC01 FPLW1KD FLBST01 FBASIAD, FBASIHD, FBASITD, FBBASHD, FBBASTD, FTAS2HD GUPUR-01 DP354ED, DP355ED, DP354HD (32 row(s) affected)
bu sorgu için tesekkür ederim işime yarayacak,
Bir materialin altında tanımlı olan 2. seviye componentin aynısından aynı materialin 3. seviyesinde de varmı bunun sorgusunu nasıl yapabilrim yardımcı olursanız sevınırım.