Is there any easy way to return single scalar or default value if query doesn't return any row?
At this moment I have something like this code example:
IF (EXISTS (SELECT * FROM Users WHERE Id = @UserId))
SELECT Name FROM Users WHERE Id = @UserId
ELSE
--default value
SELECT 'John Doe'
How to do that in better way without using IF-ELSE?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…