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 2005 Forums
 Transact-SQL (2005)
 Is is possible to create this result set?

Author  Topic 

neo302
Starting Member

30 Posts

Posted - 2007-09-28 : 15:10:21
From a query?

Sample data:
ID c1 c2 c3 c4
1 a b d

Can I create a result set of:
Column1 Column2
c1 a
c2 b
c4 d

Notice how c3 is not shown.

Thanks!!!

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-09-28 : 15:31:36
select 'c1' as Column1, c1 as Column2
from tbl where c1 is not null
union all
select 'c2', c2
from tbl where c2 is not null
union all
select 'c3', c3
from tbl where c3 is not null
union all
select 'c4', c4
from tbl where c4 is not null


- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

neo302
Starting Member

30 Posts

Posted - 2007-09-28 : 15:42:36
quote:
Originally posted by jsmith8858

select 'c1' as Column1, c1 as Column2
from tbl where c1 is not null
union all
select 'c2', c2
from tbl where c2 is not null
union all
select 'c3', c3
from tbl where c3 is not null
union all
select 'c4', c4
from tbl where c4 is not null


- Jeff
http://weblogs.sqlteam.com/JeffS





NIIIIIIIIICCCCCCE.

Thanks Jeff!!!
Go to Top of Page
   

- Advertisement -