Reputation: 2095
my ms access table like this:
ID | Group | Detail(A) | Detail(B)
1 | A | ABC |
2 | A | DEF |
3 | B | | GHI
How can my access sql select Detail(A) as 'Details' when Group=A, Detail(B) as 'Details' when Group=B ?
Thanks
Upvotes: 2
Views: 2263
Reputation: 4993
I like Remou's answer, the IIF is a good simple function, however if you are comparing multiple values, it could quickly grow to fit all the IIF's, as an alternative in a multi scenario or even for singles values if you wish you can use the Switch method:
SELECT Switch(Group="A", DetailA, Group="B", DetailB) AS Detail
FROM Table
Then you would simply keep adding e.g. Group="C", DetailC etc
Upvotes: 1
Reputation: 91336
You can use immediate if, IIF.
SELECT IIf(Group="A",DetailA,DetailB) As Detail
FROM Table
Upvotes: 2