SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Is is possible to create this result set?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

neo302
Starting Member

30 Posts

Posted - 09/28/2007 :  15:10:21  Show Profile  Reply with Quote
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

USA
7423 Posts

Posted - 09/28/2007 :  15:31:36  Show Profile  Visit jsmith8858's Homepage  Reply with Quote
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

Edited by - jsmith8858 on 09/28/2007 15:31:58
Go to Top of Page

neo302
Starting Member

30 Posts

Posted - 09/28/2007 :  15:42:36  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000