tags:

views:

2757

answers:

3

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.

+4  A: 

Jet (the database engine behind Access) SQL also supports the Nz function. Note though that Nz is the same as the T-SQL ISNULL function. It can not take an arbitary number of parameters like COALESCE can.

pipTheGeek
"Jet (the database engine behind Access) SQL also supports the Nz function" - Incorrect, Jet has no NZ() function. The MS Access object model has a NZ() function which can be used in queries only within the MS Access interface. Using NZ() outside of the MS Access interface causes an error.
onedaywhen
+3  A: 

If it's in an Access query, you can try this:

"Price = IIf([Price] Is Null,0,[Price])"
Codewerks
+2  A: 

Looks like I can just use:

SELECT ProductId, Nz(Price, 0)
FROM Products

Seems to be working just fine.

Nathan DeWitt
You do need to be careful about the resulting data type of the argument, as it doesn't always end up numeric when you expect it to. I've never quite figured out a pattern of why, though theoretically, it's supposed to pick up the data type of the first argument.
David-W-Fenton