tuzojazz Posted August 4, 2006 Share Posted August 4, 2006 Hi:I have this querySELECT SUM(Total) FROM CargoD Where Folio=100there are no records in the table "CargoD" Where Folio=100 and I get a null resulthow could I write the query in order to get 0 instead of null?Thanks!! Link to comment Share on other sites More sharing options...
murfitUK Posted August 5, 2006 Share Posted August 5, 2006 You could use the COALESCE keyword:SELECT COALESCE (query, 0);It returns the first non-null value from the list inside the brackets. So if query returns null then coalesce will return 0 as 0 is the first non-null value from the list inside the brackets.This comes from: http://dev.mysql.com/doc/refman/4.1/en/com...-operators.htmlCOALESCE(value,...)Returns the first non-NULL value in the list, or NULL if there are no non-NULL values.mysql> SELECT COALESCE(NULL,1); -> 1mysql> SELECT COALESCE(NULL,NULL,NULL); -> NULLCOALESCE() was added in MySQL 3.23.3. Link to comment Share on other sites More sharing options...
nomore_sr Posted August 20, 2006 Share Posted August 20, 2006 Hi:I have this querySELECT SUM(Total) FROM CargoD Where Folio=100there are no records in the table "CargoD" Where Folio=100 and I get a null resulthow could I write the query in order to get 0 instead of null?Thanks!!This querySELECT IsNull(SUM(Total),0) FROM CargoD Where Folio=100 will return 0 if there are no records and sum if sum is not null Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now