My table:
Users (userID, col1, col2)
I want to make a generic stored procedure, but I need to return EITHER col1 or col2 in a query.
Can I case statement handle this situation?
SELECT userID, col1
FROM Users
OR
SELECT userID, col2
FROM Users
casesql serversql-server-2008
My table:
Users (userID, col1, col2)
I want to make a generic stored procedure, but I need to return EITHER col1 or col2 in a query.
Can I case statement handle this situation?
SELECT userID, col1
FROM Users
OR
SELECT userID, col2
FROM Users
Best Answer
Using CASE:
Using COALESCE:
COALESCE returns the first column value that isn't null, starting from the left.