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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Convert rows to columns

Author  Topic 

kiran
Starting Member

30 Posts

Posted - 2004-04-13 : 13:22:39
Is there is any way to convert rows to columns in SQL Server ?

An Example (The data could grow more) :

servers 2
printers 25
CPU 700
....
....

What I need to do is convert the rows into columns. I want it to look like this:

servers printers CPU
2 25 700

Here is the simple query that gets me my results:

Select asset_cateogry, count(asset_category)
from tableName
group by asset_category

Thanks in advance...

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-04-13 : 13:27:25
http://www.sqlteam.com/item.asp?ItemID=2955

Tara
Go to Top of Page

kiran
Starting Member

30 Posts

Posted - 2004-04-13 : 13:44:25
Thank you very much Tara. What if i don't have any grouping or sum columns. If it is a simple query but values are not definite.

Ex:

Select PropertyName, PropertyValue From problems

PropertyName PropertyValue
------------ ------------
FirstName Jason
LastName Gold
Phone 111-111-111
... ....
FirstName George
LastName Mathews
Phone 222-222-222
....

How to convert this to

FirstName LastName Phone .... .....
--------- -------- ----- ----- -------
Jason Gold 111-111-1111 .... ....
George Mathews 222-222-2222 .... .....
..... ....... ...... .... .....

My problem is PropertyNames are not definite.. they can grow...

Thanks again...
Go to Top of Page
   

- Advertisement -