Click here to Skip to main content
15,867,958 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
SQL
SELECT SUM(Pairs) AS previous_pairs FROM payout 
WHERE user_id = '100001'


above query works fine if there are record present in the table. If there are not single row with id '100001', then it returns NULL.

What i want is if there are no row present with id '100001' then it should return 0 instead of NULL.

Any help would be appreciated.
Posted

SQL
SELECT ISNULL(SUM(Pairs), 0) AS previous_pairs FROM payout
WHERE user_id = '100001'
 
Share this answer
 
Comments
Maciej Los 24-Feb-14 5:06am    
+5
Nandakishore G N 24-Feb-14 5:26am    
good answer...My 5..
Joezer BH 25-Feb-14 4:34am    
5ed!
ISNULL function as: http://technet.microsoft.com/en-us/library/ms184325.aspx[^]

It checks whether expression returns null, then replaces it with what you provide as replacement value.
 
Share this answer
 
Another way is to use COALESCE()[^] function.
 
Share this answer
 
select ISNULL(NickName,'0') as ppb from Users where UserId='37'



here, NickName is column name
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900