Reputation: 1341
I have my Access table linked to SQL server. I have created linked view where I have replaced the nz() function
with COALESCE function
. However, I am not sure if I have to convert nz function
to COALESCE
in VBA
as well.
For example for the code below:
rst.Open "SELECT * FROM table1", CurrentProject.Connection, adOpenStatic, adLockReadOnl
y
I have
IF NZ('Field1',0) =0 then
//do something
Should I do
IF COALESCE('Field1',0) =0 then
//do something
Or do I only need to change it in my SQL query?
Upvotes: 1
Views: 745
Reputation: 20342
I'd stick with the NZ() function in Access, and if you want to handle this on the SQL Server side, before pulling it into Access, that's another option. In SQL Server, The COALESCE() function returns the first non-null value in a list.
Upvotes: 0
Reputation: 5677
Coalesce
is a feature only available in T-SQL
it isn't a VBA function.
It's up to you how you want to handle converting nulls into a new value, there are many ways to do this. You can check your variables before adding them to a SQL statement, or, you can alter them as part of the SQL with Coalesce
, IsNull
or Case
.
Personally, I would do whatever is less code that still gets the idea across clearly. I'd imagine this would be decided on a case by case basis depending what it is you are doing.
Upvotes: 1