|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Two columns in 1 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|