Reputation: 4663
I want the query to return the distance if the user has opted to show their position. This is what I have:
SELECT
showpos,
CASE distance WHEN showpos=1 THEN distance ELSE "N/A" END
FROM table
I also have a case statement for showpos (1=True/0=False) but this does not have any errors. This is not returning the correct results. How do I make it show distance only when showpos=1 and return "N/A" when showpos=0?
Original data:
After Query Results:
Upvotes: 0
Views: 204
Reputation: 180260
SELECT showpos,
CASE WHEN showpos = 1 THEN distance ELSE 'N/A' END
FROM mytable
or
SELECT showpos,
CASE showpos WHEN 1 THEN distance ELSE 'N/A' END
FROM mytable
Upvotes: 2