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)
 Converting Values to columns name

Author  Topic 

csi123
Starting Member

1 Post

Posted - 2008-09-06 : 20:47:06
Hi,
This will b of g8 help .

There is a table which has the following values
Column X columnY
X1 Yes
X2 No
X3 Yes

Is it possible to get the output as,

COLUMND HEADING AS X1 X2 X3
AND VALUES Yes No Yes

THANKS

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-07 : 02:41:49
Do you have any other column in yourtable?Also wont X1,X2,.. repeat?
Go to Top of Page

yonabout
Posting Yak Master

112 Posts

Posted - 2008-09-17 : 06:49:38
Hi,

you could try this:

create table #temp(X varchar(2), Y varchar(3))

insert into #temp
select 'X1', 'Yes' union all
select 'X2', 'No' union all
select 'X3', 'Yes'

select
max(case when x = 'X1' then y end) as 'X1',
max(case when x = 'X2' then y end) as 'X2',
max(case when x = 'X3' then y end) as 'X3'
from #temp

but you will end up having to cater for all the x[n] rows in your table.

What are you trying to do?

Cheers,

Yonabout
Go to Top of Page
   

- Advertisement -