try this:
if object_id('dbo.TblSchedule') is not null
drop table dbo.TblSchedule
Create table dbo.TblSchedule
(
[Date] DATE,
EmpName VARCHAR(50),
ShiftName VARCHAR(50)
)
insert into dbo.TblSchedule values
('07/19/2015','Tony','Morning'),
('07/19/2015','Jack','Afternoon'),
('07/19/2015','Tony','Night'),
('07/19/2015','Mohit','Night'),
('07/20/2015','Rocky','Morning'),
('07/20/2015','Jocky','Afternoon'),
('07/20/2015','Man','Afternoon'),
('07/20/2015','Romy','Night')
;with CTE AS
(
SELECT [DATE],ShiftName, EmpName =
STUFF((SELECT ', ' + EmpName
FROM dbo.TblSchedule b
WHERE b.[Date] = a.[Date] and b.ShiftName = a.ShiftName
FOR XML PATH('')), 1, 2, '')
FROM dbo.TblSchedule a
GROUP BY [Date],ShiftName
)
select ts.[Date],max(cmorning.EmpName) as MorningShift,max(cafternoon.EmpName) as AfternoonShift,max(cNight.EmpName) as NightShift
from dbo.TblSchedule ts
LEFT JOIN CTE cmorning on ts.[Date] = cmorning.[Date] and cmorning.ShiftName = 'Morning'
LEFT JOIN CTE cafternoon on ts.[Date] = cafternoon.[Date] and cafternoon.ShiftName = 'Afternoon'
LEFT JOIN CTE cNight on ts.[Date] = cNight.[Date] and cNight.ShiftName = 'Night'
group by ts.[Date]
ORDER BY Ts.[Date]