Jump to content

sum


tuzojazz

Recommended Posts

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

  • 3 weeks later...
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 query
SELECT 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...