Quantcast
Channel: Help in Transpose format result
Viewing all articles
Browse latest Browse all 7

Help in Transpose format result

$
0
0
Create table #temp (ECode char(20), lastName char(20), FirstName char(20), Bdate datetime)
Insert into #temp values ('12','Samad','Irhad','1967-01-10')
 , ('34','Smith','Peter','1968-01-20')
 , ('99','Farhan','Ji','1989-02-19')
 , ('44','Jina','Farah','1997-03-05')
 , ('41','David','Bhi','1997-06-05')
 , ('53','Sam','David','1972-07-01')
 , ('17','Kila','Sam','1972-04-01')
 , ('19','Sarah','G','1996-05-08')
 , ('67','Jinnah','F','1996-08-08')
 , ('41','Rose','D','1995-09-05')
 , ('53','Sam','T','1975-10-01')
 , ('67','Joe','G','1997-10-08')
 , ('53','Piya','SW','1962-12-01')
 , ('67','Bhani','Q','1992-12-07')
 , ('41','Mira','Dr','1987-11-05');
;with mycte as (
Select 
Concat(RTRIM(LastName),',',RTRIM(FirstName), ' - ', Right('0'+Cast(datepart(day,Bdate) as varchar(2)),2) ) grp
,Left(datename(month,Bdate),3) mnth 
,ROW_NUMBER() over (partition by Left(datename(month,Bdate),3) order by datepart(day, BDate)) as Rn
from  #temp
)

select  
Max(case when mnth='Jan' then    grp  else null end ) 'Jan'
,Max(case when mnth='Feb' then    grp  else null end ) 'Feb'
,Max(case when mnth='Mar' then    grp  else null end ) 'Mar'
,Max(case when mnth='Apr' then    grp  else null end ) 'Apr'
,Max(case when mnth='May' then    grp  else null end ) 'May'
,Max(case when mnth='Jun' then    grp  else null end ) 'Jun'
,Max(case when mnth='Jul' then    grp  else null end ) 'Jul'
,Max(case when mnth='Aug' then    grp  else null end ) 'Aug'
,Max(case when mnth='Sep' then    grp  else null end ) 'Sep'
,Max(case when mnth='Oct' then    grp  else null end ) 'Oct'
,Max(case when mnth='Nov' then    grp  else null end ) 'Nov'
,Max(case when mnth='Dec' then    grp  else null end ) 'Dec'
from mycte
group by rn


drop table #temp


Viewing all articles
Browse latest Browse all 7

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>