Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

La stessa unità SQL tra due tabelle richiede numeri d'ordine in 1 cella

select 
    UnitId, 
    stuff((select ', ' + convert(varchar, WorkOrderNumber) 
           from tblWorkOrders t2 where t1.UnitId = t2.UnitId 
           for xml path('')),
          1,2,'') WorkOrderNumbers
from tblWorkOrders t1
group by UnitId