Reputation: 157
I have a SQL query
SELECT s.id,
s.First_Name +' '+s.Last_Name AS Name,
d1.Department_Name,
s.Manager_Id,
s.EmailId
FROM Fin_UserMaster s
INNER JOIN Fin_Department_Master AS d1 ON d1.id = s.Department_Id
WHERE s.id =
(SELECT Manager_Id
FROM Fin_UserMaster
WHERE id= '13')
Now if my nested query returns null I want to give another Id in place of nested query.
For example, if nested query returns null then s.id = '13'
, something like that.
Tried a few things, but they didn't work out.
Upvotes: 2
Views: 929
Reputation: 33474
(select COALESCE(Manager_Id, 13) from Fin_UserMaster where id= '13')
OR
(select ISNULL(Manager_Id, 13) from Fin_UserMaster where id= '13')
EDIT: Over a large number of rows, ISNULL
seems to be faster. However, it isn't part of SQL standard - as some of the answers on ISNULL vs COALESCE suggest.
Upvotes: 4