How to Show Column Data as a Rows with Pivot
--Code for create table with columns (id,attribute,value)
create table t1 (
id int,
attribute varchar(50),
value varchar(100)
)
--Code for Insert Value in Table with columns (id,attribute,value)
insert into t1(id, attribute, value)
values
(1, 'stu_name', 'Rahul'),
(1, 'address', 'Mahipalpur'),
(1, 'Qualification', 'BTech'),
(2, 'Stu_name', 'Sakshi'),
(2, 'address', 'Greater Noida'),
(2, 'Qualification', 'BTech'),
(3, 'Stu_name', 'Kush Tiwari'),
(3, 'address', 'Noida'),
(3, 'Qualification', 'MCA')
--Code for View the data of Table with columns (id,attribute,value)
select * from t1
--Code for View the data of Table with columns (id,Student Name,address,Qualification)
select
pvt.id,
pvt.stu_name as [Student Name],
pvt.address,
pvt.Qualification
from t1
pivot (
min(value)
for attribute in ([stu_name],[Address],[Qualification])
) pvt
No comments:
Post a Comment