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.
| Author |
Topic |
|
lane0618
Posting Yak Master
134 Posts |
Posted - 2003-05-01 : 20:20:02
|
| I have the follwing query:SELECT nodePairA, nodePairBFROM Tree2TreePairWHERE (nodePairA = 'A08') OR (nodePairB = 'A08')results:nodePairA nodePairBA08 A0BA08 A10A08 A16A08 A18A08 A22A21 A08A20 A08I want to end up with a single column with any set that has A08 in it, so I wound end up with:ConsolidatedPairA0BA10A16A18A22A21A20 Thanks in Advance! |
|
|
spromtet
Starting Member
7 Posts |
Posted - 2003-05-01 : 21:09:57
|
| I think this should work. I might not understand what you're trying to do.SELECT ConsolidatedPair = CASE WHEN nodePairA= 'A08' THEN nodePairB WHEN nodePairB = 'A08' THEN nodePairA END FROM Tree2TreePair WHERE (nodePairA = 'A08') OR (nodePairB = 'A08') |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2003-05-01 : 21:10:11
|
| SELECT case when nodepairA = 'A08' then NodePairB else NodePaidA end as NodeFROM Tree2TreePair WHERE (nodePairA = 'A08') OR (nodePairB = 'A08') - Jeff |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2003-05-01 : 21:11:17
|
| Ah! you beat me by like 10 seconds. but mine is shorter! you don't need to test for two conditions -- the WHERE clause takes care of that.- Jeff |
 |
|
|
byrmol
Shed Building SQL Farmer
1591 Posts |
Posted - 2003-05-01 : 21:54:08
|
SELECT case when nodepairA = 'A08' then NodePairB else NodePaidA end as Node FROM Tree2TreePair WHERE 'A08' IN (nodePairA, nodePairB) And that is shorter still.....DavidM"SQL-3 is an abomination.." |
 |
|
|
Arnold Fribble
Yak-finder General
1961 Posts |
Posted - 2003-05-02 : 04:28:21
|
Can I play?  SELECT COALESCE(NULLIF(nodePairA, 'A08'), nodePairB) AS NodeFROM Tree2TreePair WHERE 'A08' IN (nodePairA, nodePairB) |
 |
|
|
|
|
|