Home > Database > Mysql Tutorial > How to Replace NULL Values in Access SQL: The Equivalent of COALESCE?

How to Replace NULL Values in Access SQL: The Equivalent of COALESCE?

Linda Hamilton
Release: 2025-01-08 00:45:44
Original
268 people have browsed it

How to Replace NULL Values in Access SQL: The Equivalent of COALESCE?

Equivalent of the COALESCE function in Access SQL

The COALESCE function is commonly used in SQL Server (T-SQL) to return the first non-NULL value from a parameter list. In Access SQL, the IIF function has similar functionality.

Solution:

To implement the function of COALESCE in Access SQL, you can use the IIF function. The syntax is as follows:

<code>IIf([表达式], TruePart, FalsePart)</code>
Copy after login

In this example, to replace the NULL value in the Price field with 0:

<code>"Price = IIf([Price] Is Null, 0, [Price])"</code>
Copy after login

This expression evaluates whether the Price field is NULL. If true, returns 0; otherwise, returns the Price value itself.

By incorporating this expression into the query, you can handle NULL values ​​efficiently:

<code>SELECT ProductId, "Price = IIf([Price] Is Null, 0, [Price])" AS Price
FROM Products</code>
Copy after login

This query returns the ProductId and modified Price columns, where NULL values ​​have been replaced with 0.

The above is the detailed content of How to Replace NULL Values in Access SQL: The Equivalent of COALESCE?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template