Declare @year varchar(max)=''
@year= Stuff((SELECT ', [' + cast(s as varchar(max))+']'
(SELECT DISTINCT DATEPART(YYYY,Sdate) as s FROM dbo.StudDet
For XML PATH ('')),1,1,'')
select cast(DATEPART(MONTH,Sdate) as varchar(max)) as Months,Score,
DATEPART(year,Sdate) as st
for st in('+@year+')
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)