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:
You can drop the if statement using following construct but that doesn't necessarely mean it is better.
SELECT Name FROM Users WHERE Id = @UserId UNION ALL SELECT 'John Doe' WHERE NOT EXISTS (SELECT Name FROM Users WHERE Id = @UserId)