Reputation: 111
Under SQL Server 2008, I want to return 0 value if there is no row found. I have tried my best but I failed. Please suggest me.
My requirement is:
myNullValue
-----------
0
SELECT (
CASE
WHEN NoOfDue IS NULL
THEN 0
ELSE NoOfDue
END
) myNullValue
FROM (
SELECT COUNT(LHID) AS NoOfDue
FROM dbo.TblLoanHistory
WHERE (
LHEMIPaid = 0
OR LHEMIPaid IS NULL
)
AND LHAcNo = '010575100000114'
GROUP BY LHEMI
) aa
Upvotes: 0
Views: 476
Reputation: 204746
select top 1 * from
(
SELECT COUNT(LHID) AS NoOfDue
FROM dbo.TblLoanHistory
WHERE (LHEMIPaid=0 OR LHEMIPaid is null)
and LHAcNo='010575100000114'
GROUP BY LHEMI
union
select 0 as NoOfDue
) x
order by NoOfDue
Upvotes: 1