In T-SQL, you can do this:
SELECT ProductId, COALESCE(Price, 0) FROM Products
How do you do the same thing in Access SQL? I see examples for doing it with Nz in VBA, but I'm looking for the SQL equivalent.
Thanks.
IFNULL checks a single argument. COALESCE works with N arguments. COALESCE is useful when you have unknown number of values that you want to check. IFNULL is useful when you select columns and know that it can be null but you want to represent it with a different value.
advantage that COALESCE has over ISNULL is that it supports more than two inputs, whereas ISNULL supports only two. Another advantage of COALESCE is that it's a standard function (namely, defined by the ISO/ANSI SQL standards), whereas ISNULL is T-SQL–specific.
In my experience, there is no significant performance difference among them. If you need to compare only one value, I would go with ISNULL() function. If you need to compare more than one expression you can use COALESCE since you need to write less code. There is nothing wrong with using CASE statement either.
Access supports the Nz
function and allows you to use it in a query. Note though that Nz
is the same as the T-SQL ISNULL
function. It can not take an arbitrary number of parameters like COALESCE
can.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With