Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
HelloI have requirement like I am maintaining a student monthly exam report ..I have a table tblExam where data containing like this..Class Month heldornot Class1 Jan YesClass1 Feb YesClass1 Mar YesClass1 April NoClass2 Jan YesClass2 Feb yesClass2 MAR NoClass2 April NoNow if I will generate 2 Exam report from 1) Jan to March 2) Jan to Aprilthen result will be Report 1Class Jan Feb MarchClass 1 Yes Yes YesClass 1 Yes Yes NoReport 2Class Jan Feb March AprilClass 1 Yes Yes Yes YesClass 1 Yes Yes No NoI want to display above report in gridview...Thanks and RegardsGyana Ranjan Ojha
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2010-01-07 : 02:32:39
make use of pivot
SELECT Class,Jan,Feb,Mar,AprFROM table tPIVOT (MAX(heldornot) FOR [Month] IN (Jan,Feb,Mar,Apr))p
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2010-01-07 : 02:33:37
and use this if you want to do it dynamicallyhttp://sqlblogcasts.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx
gyana.ojha
Starting Member
5 Posts
Posted - 2010-01-07 : 02:45:11
Thank you but month will based on selection of month from and toLike if user select month from Jan to AugThen column will be shown likeJan Feb march April March - - - - - - - AugustIf user will select month from jan to SeptThen column will be display as Jan Feb March April March - - - - - - September
quote:Originally posted by visakh16 make use of pivot
SELECT Class,Jan,Feb,Mar,AprFROM table tPIVOT (MAX(heldornot) FOR [Month] IN (Jan,Feb,Mar,Apr))p