| Author |
Topic |
|
rajeeshmca
Starting Member
3 Posts |
Posted - 2009-10-30 : 03:34:09
|
| HiIs it possible to select more than one field within a case?Eg:Assume a table has 5 fields Field1, Field2, Field3, Field4, Field5selectcase Field5when 'A' thenField1, Field2when 'B' thenField3, Field4endIs this possible?? If so how?Rajeesh |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-10-30 : 03:42:04
|
Nope Not possible. You have to use the case statement on every one of themselect case Field5 when 'A' then Field1 when 'B' then Field3 end, case Field5 when 'A' then Field2 when 'B' then Field4 end KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
rajeeshmca
Starting Member
3 Posts |
Posted - 2009-10-30 : 04:01:20
|
| Is there any other way other than using case?Rajeesh |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-10-30 : 04:27:03
|
| select Field1, Field2 from your_table where Field5='A'select Field3, Field4 from your_table where Field5='B'MadhivananFailing to plan is Planning to fail |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-10-30 : 05:08:17
|
you missed out the UNION ALLselect Field1, Field2 from your_table where Field5='A' UNION ALLselect Field3, Field4 from your_table where Field5='B' KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
rajeeshmca
Starting Member
3 Posts |
Posted - 2009-10-30 : 05:48:07
|
| thanks for tht.. this worksRajeesh |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-10-30 : 08:40:20
|
quote: Originally posted by khtan you missed out the UNION ALLselect Field1, Field2 from your_table where Field5='A' UNION ALLselect Field3, Field4 from your_table where Field5='B' KH[spoiler]Time is always against us[/spoiler]
Thanks MadhivananFailing to plan is Planning to fail |
 |
|
|
Pradip
Starting Member
32 Posts |
Posted - 2009-10-31 : 08:21:57
|
| Hi Rajesh,Assume a table has 5 fields Field1, Field2, Field3, Field4, Field5selectcase Field5when 'A' thenField1, Field2when 'B' thenField3, Field4endit is possiblelike thisselectcase Field5 when 'A' then Field1 when 'B' then Field3 end, case Field5 when 'A' then Field2 when 'B' then Field4endendIs it ok ...pradipjain |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-10-31 : 09:14:42
|
quote: Originally posted by Pradip Hi Rajesh,Assume a table has 5 fields Field1, Field2, Field3, Field4, Field5selectcase Field5when 'A' thenField1, Field2when 'B' thenField3, Field4endit is possiblelike thisselectcase Field5 when 'A' then Field1 when 'B' then Field3 end, case Field5 when 'A' then Field2 when 'B' then Field4endendIs it ok ...pradipjain
OP wanted without the use of CASE expressionMadhivananFailing to plan is Planning to fail |
 |
|
|
|