Neat SQL trick

One of the guys here just alerted me to a neat little SQL trick that I thought I would share.

I often use count() and sum() to get totals out of the database but I always have issues when there are no records to count and so my nice, neat recordset has empty gaps.

If you want to make it nicer, just change the SQL statment to use the isNull() function!

so, your SQL used to look like:

sum(total) as balance

now looks like:

isNull(sum(total),0) as balance

and now it will always return a number!
cool hey?

This entry was posted in General.