Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

How to convert rows into columns in sql server 2000

This is a discussion on How to convert rows into columns in sql server 2000 within the SQL Server forums, part of the Databases category; Hi, suppose the input is, name1 id1 id2 id3 id4 name2 id1 id2 id3 id4 I want the output as in the database, name1 id1 name1 id2 name1 id3 name1 ...

Go Back   Geeks Talk > Databases > SQL Server
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read

SQL Server SQL Server is a Database Management System(DBMS) by Microsoft

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-27-2009
Junior Member
 
Join Date: Jul 2009
Location: bangalore
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
latha_a12 is on a distinguished road
How to convert rows into columns in sql server 2000

Hi,

suppose the input is,

name1 id1 id2 id3 id4

name2 id1 id2 id3 id4

I want the output as in the database,

name1 id1

name1 id2

name1 id3

name1 id4

name2 id1

name2 id2

name2 id3

name2 id4

Please help me out on solving this in sql server 2000.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-27-2009
Contributing Member
 
Join Date: Jun 2009
Location: United States
Posts: 71
Thanks: 0
Thanked 5 Times in 4 Posts
CSOOR is on a distinguished road
Re: How to convert rows into columns in sql server 2000

Quote:
Originally Posted by latha_a12 View Post
Hi,

suppose the input is,

name1 id1 id2 id3 id4

name2 id1 id2 id3 id4

I want the output as in the database,

name1 id1

name1 id2

name1 id3

name1 id4

name2 id1

name2 id2

name2 id3

name2 id4

Please help me out on solving this in sql server 2000.
Please take the idea from one of my answer for "One row to Multiple Rows" in the same sql server thread.
The member name is "kkknnn" .

Last edited by CSOOR; 07-27-2009 at 05:00 PM.
Reply With Quote
  #3 (permalink)  
Old 08-26-2009
Junior Member
 
Join Date: Aug 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
jessym is on a distinguished road
Re: How to convert rows into columns in sql server 2000

SELECT <non-pivoted column>,

[first pivoted column] AS <column name>,

[second pivoted column] AS <column name>,

...

[last pivoted column] AS <column name>

FROM

(<SELECT query that produces the data>)

AS <alias for the source query>

PIVOT

(

<aggregation function>(<column being aggregated>)

FOR

[<column that contains the values that will become column headers>]

IN ( [first pivoted column], [second pivoted column],

... [last pivoted column])

) AS <alias for the pivot table>

<optional ORDER BY clause>;
Reply With Quote
Reply

  Geeks Talk > Databases > SQL Server

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Identify Rows columns in datagrid control kanta QTP 8 07-31-2008 05:11 PM
How can we write the columns set as rows set? nageshkota SQL Server 4 04-29-2008 01:16 AM
Rows to columns and vice-versa tanya_j Data Warehousing 1 03-25-2008 06:49 AM
How to convert rows into columns in Teradata rashnyo Data Warehousing 0 07-12-2007 01:52 AM
How do I transpose Rows into Columns? Anasuya1031 SQL 2 07-09-2007 05:37 AM


All times are GMT -4. The time now is 07:23 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved