MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 7th, 2004, 10:17 AM
Providence77 Providence77 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 24 Providence77 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 48 m 24 sec
Reputation Power: 0
Two columns in 1

I have the following table:
CliData
Name WantFax WantEmail Fax Email
Pippo Y N 0123 em@012
Pluto Y Y 3456 em@456
Topo N N 7890 em@890

I would like to build a query to generate a result like :
NAME Fax/Email
Pippo 0123
Pluto 3456
Pluto em@456

I'd like to see under the same column (Fax/EMail or whatever) either the Fax number or Email address or both, depending on WantFax and WantEmail values (Yes or Not).
Is it possible?

Thanks
Stefano

Reply With Quote
  #2  
Old October 7th, 2004, 12:31 PM
Username=NULL Username=NULL is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: TX
Posts: 249 Username=NULL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 7 h 6 m 42 sec
Reputation Power: 5
Send a message via Yahoo to Username=NULL
Here's the table data a little cleaner looking...
Code:
Name	WantFax	WantEmail	Fax Email
-----	-------	---------	---------
Pippo 	Y	 N		0123 em@012
Pluto	Y	 Y		3456 em@456
Topo 	N	 N		7890 em@890

This is the best I could come up with...
Code:
Select	Name,
	Case
	  When WantFax = 1 Then Fax
	  Else null
	End [Email],
	Case
	  When WantEmail = 1 Then Email
	  Else null
	End [Fax]
from	cliData
where   wantsFax = 1
or      wantsEmail = 1

What you're doing when you're printing a seperate row based on whether or not the record name wants an email and/or a fax isn't the most accepted approach. Breaking out the fax and email in their own fields and just returning 1 record per name (if wantsEmail OR wantsFax is Y) would be a better approach IMO.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Two columns in 1


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT