SQLTeam.com | Weblogs | Forums

Combine multiple rows into one row in sql


#1

Need help to merge all the rows into a single row, can anybody help me please!!
Here's my query and OUTPUT
SELECT BNBEN.EMPLOYEE AS SUB_EMPLOYEE,
BNBEN.PLAN_CODE AS SUB_PLAN_CODE,
BNBEN.EMP_COST AS SUB_EMP_COST
FROM BNBEN
WHERE ((BNBEN.EMPLOYEE IN (1666, 1712) AND BNBEN.PLAN_TYPE='RS')
OR (BNBEN.EMPLOYEE IN (1666, 1712) AND BNBEN.PLAN_CODE IN ('MEDW','MED1','MED4')))

Sub_Employee Sub_Plan_Code Sub_Emp_Cost
166 MED4 57.87
166 FSAM 100.00
166 FSDW 0.00
166 HSAV 230.77
166 NLSF 0.00
172 MED4 22.80
172 FSAD 192.31
172 FSMW 0.00
172 HSAV 269.23
172 LSFS 101.92

OUTPUT SHOULD BE LIKE BELOW
Sub_Emp MED4 FSAM FSDW HSAV NLSF FSAD FSMW LSFS
166 57.87 100.00 0.00 230.77 0.00 null null null
172 22.80 null null 269.23 null 192.31 0.00 101.92


#2

Use same princip as this