Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

coalesce alternative in Access SQL

Tags:

sql

ms-access

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.

like image 982
Nathan DeWitt Avatar asked Oct 29 '08 18:10

Nathan DeWitt


People also ask

Is COALESCE same as Ifnull?

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.

Which is better Isnull or COALESCE?

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.

Is COALESCE better than case?

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.


1 Answers

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.

like image 183
pipTheGeek Avatar answered Oct 16 '22 04:10

pipTheGeek