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)
 row to column

Author  Topic 

jung1975
Aged Yak Warrior

503 Posts

Posted - 2005-08-23 : 11:51:23
How can I covert row to column?

Population moderate High
100 60 40


to

Population 100
moderate 60
High 40


mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2005-08-23 : 15:01:19
[code]SELECT
'population' AS MyColumn1,
mt.population AS MyColumn2
FROM
dbo.MyTable AS mt
UNION
SELECT
'moderate',
mt.moderate
FROM
dbo.MyTable AS mt
UNION
SELECT
'high',
mt.high
FROM
dbo.MyTable AS mt[/code]
If you want to do this dynamically, you'll need to construct the SQL using metadata (information_schema.columns).

Mark
Go to Top of Page
   

- Advertisement -