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
 SQL Server Development (2000)
 Query Help

Author  Topic 

mahesh_bote
Constraint Violating Yak Guru

298 Posts

Posted - 2006-10-19 : 09:08:29
hi,

i have one table with three columns.
i.e.

A B C ---> Columns
1 2 3 ---> Data
3 2 1 ---> Data
1 3 2 ---> Data

now i want o/p like

ColumnName Value
A 1
B 2
C 3
A 3
B 2
C 1
A 1
B 3
C 2

its an example, actually i have nearabt 54 columns and i want to return them in mentined manner.

thanks in advance,
Mahesh

nr
SQLTeam MVY

12543 Posts

Posted - 2006-10-19 : 09:23:33
select columnname = 'A', value = A from tbl
union all
select columnname = 'B', value = B from tbl
union all
select columnname = 'C', value = C from tbl


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

mahesh_bote
Constraint Violating Yak Guru

298 Posts

Posted - 2006-10-20 : 02:50:05
thanks,

but as i have mentioned earlier, i have table with 54 columns and it contains 65 rows. i wants to write the sql statement which will show the value beside the columns name.



Mahesh
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-10-20 : 03:01:36
quote:
Originally posted by mahesh_bote

thanks,

but as i have mentioned earlier, i have table with 54 columns and it contains 65 rows. i wants to write the sql statement which will show the value beside the columns name.



Mahesh


Just add on to the union all as what nr had demonstrate here

select columnname = 'A', value = A from tbl
union all
select columnname = 'B', value = B from tbl
union all
select columnname = 'C', value = C from tbl
union all
select columnname = 'D', value = D from tbl




KH

Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2006-10-20 : 06:44:40
when i see "now i want o/p like" i read it as "Now i want to present the data in this format", and that type of operation is best done in the Madhi.

I mean front end.



[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-21 : 06:53:24
>> and that type of operation is best done in the Madhi.




Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-21 : 06:58:38
quote:
Originally posted by mahesh_bote

hi,

i have one table with three columns.
i.e.

A B C ---> Columns
1 2 3 ---> Data
3 2 1 ---> Data
1 3 2 ---> Data

now i want o/p like

ColumnName Value
A 1
B 2
C 3
A 3
B 2
C 1
A 1
B 3
C 2

its an example, actually i have nearabt 54 columns and i want to return them in mentined manner.

thanks in advance,
Mahesh



Where do you want to show data?
If you use vb or asp you can very well do there.
It cant be done in sql easily as you expect


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -