hi , sorry to say i don't have time to give solution for your post , i have one sample code .
please have a look on this
UNPIVOT:
-------
Used to convert columns into rows
Create table tbl_stdmarksdata (studentname nvarchar(100), I int, II int, III int, IV int, V int)
go
Insert into tbl_stdmarksdata (studentname,I,II,III,IV,V)
Select 'Vivek Johari',30,20,35, 40, 45
Union All
Select 'Chandra Singh',30,20,35,44, 80
Union All
Select 'Avinash Dubey',30,25,35,20, 39
Union All
Select 'Pankaj Kumar',33,29,30, 60, 50
go
select * from tbl_stdmarksdata
go
select studentname,Marks,Grade
from tbl_stdmarksdata
unpivot
(Marks for Grade in (I,II,III,IV,V) ) as tblunpvt