Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 03, 2013 06:46 AM by sandeepmittal11
Member
620 Points
380 Posts
Feb 01, 2013 11:41 AM|LINK
hi i need help on writing a query to display my this result set
id name startdate spprovaldate approvallevel
like this
id name startdate LineManager Divisional Head BAG/CITM Manager Manager
5878 Tauqir Ud Din 2011-12-16 7/7/2011 3:26:25 PM 7/7/2011 6:47:56 PM 7/8/2011 9:44:09 AM 7/8/2011 3:11:29 PM
i have idea about pivot but not able to do this....plz help
Participant
1278 Points
195 Posts
Feb 01, 2013 12:19 PM|LINK
Hi,
Try:
select id, name, startdate, [Line Manager], [Divisional Head], [Manager], [BAG/CITM Manager] from MyTable pivot ( max(spprovaldate) for approvallevel in ([Line Manager], [Divisional Head], [Manager], [BAG/CITM Manager]) ) as PivotTable
Hope this help.
Contributor
6767 Points
1057 Posts
Feb 03, 2013 06:46 AM|LINK
If values in the coluumn approvallevel are static, then use the solution suggested by imobsuz. But, if the values are not static, you will be required dynamic pivot.
Refer below links for dynamic pivot
http://itdeveloperzone.blogspot.in/2011/11/dynamic-pivot-in-sql-server.html
http://itdeveloperzone.blogspot.in/2011/01/pivot-with-dynamic-columns.html
shumailaAjk
Member
620 Points
380 Posts
help needed in query
Feb 01, 2013 11:41 AM|LINK
hi i need help on writing a query to display my this result set
id name startdate spprovaldate approvallevel
like this
id name startdate LineManager Divisional Head BAG/CITM Manager Manager
5878 Tauqir Ud Din 2011-12-16 7/7/2011 3:26:25 PM 7/7/2011 6:47:56 PM 7/8/2011 9:44:09 AM 7/8/2011 3:11:29 PM
i have idea about pivot but not able to do this....plz help
imobsuz
Participant
1278 Points
195 Posts
Re: help needed in query
Feb 01, 2013 12:19 PM|LINK
Hi,
Try:
select id, name, startdate, [Line Manager], [Divisional Head], [Manager], [BAG/CITM Manager] from MyTable pivot ( max(spprovaldate) for approvallevel in ([Line Manager], [Divisional Head], [Manager], [BAG/CITM Manager]) ) as PivotTableHope this help.
sandeepmitta...
Contributor
6767 Points
1057 Posts
Re: help needed in query
Feb 03, 2013 06:46 AM|LINK
If values in the coluumn approvallevel are static, then use the solution suggested by imobsuz. But, if the values are not static, you will be required dynamic pivot.
Refer below links for dynamic pivot
http://itdeveloperzone.blogspot.in/2011/11/dynamic-pivot-in-sql-server.html
http://itdeveloperzone.blogspot.in/2011/01/pivot-with-dynamic-columns.html
Sandeep Mittal | My Blog - IT Developer Zone