-----------------------------------------------------------
New Message on MumbaiUserGroup
-----------------------------------------------------------
From: Star_Venkat
Message 1 in Discussion
Column to Rows and Rows to Column: I have seen many of our group members
have asked for this conversion that why i have added this topic today.
Microsoft SQL Server 2005 have introduced a new concept called Pivot. The
pivot keyword is used to convert the rows of the table to column and column of
the table to row. Below is the code in sql server 2005. -- Am trying to create
a table
CREATE TABLE dbo.VenkatTable1 (Studentname VARCHAR(25),Subject1 INT,Subject2
INT,subject3 INT)
GO
--Inserting datas into the table
INSERT INTO dbo.VenkatTable1 VALUES('Studen1', 12, 23, 43)
INSERT INTO dbo.VenkatTable1 VALUES('Student2', 34, 33, 59)
INSERT INTO dbo.VenkatTable1 VALUES('Student3', 39, 88, 77)
INSERT INTO dbo.VenkatTable1 VALUES('Student4', 34, 43, 43)
GO select * from VenkatTable1
For converting rows to column and columns to row am using the below query,
SELECT * FROM ( SELECT * FROM dbo.VenkatTable1 AS a UNPIVOT
( [Value1] FOR [Subjects] IN ([Subject1], [Subject2], [subject3])) AS unpvt
) AS tab1
PIVOT( MAX([Value1]) FOR Studentname IN ([Studen1], [Student2], [Student3],
[Student4])
) AS tab2
GO
Regards,
Venkatesan Prabu. J
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/MumbaiUserGroup/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you
received this message by mistake, please click the "Remove" link below. On the
pre-addressed e-mail message that opens, simply click "Send". Your e-mail
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]