Page 20 of 23PREVNEXT

Queries II: Limit your data and calculate values

Expression Purpose
LeadTime: IIf(IsNull([RequiredDate] - [ShippedDate]), "Check for a missing date", [RequiredDate] - [ShippedDate]) Displays in the LeadTime field the message "Check for a missing date" if the value of either the RequiredDate or ShippedDate fields is null; otherwise, it displays the difference.
CurrentCountry: IIf(IsNull([Country]), "", [Country]) Displays in the CurrentCountry field an empty string if the Country field is null; otherwise, it displays the contents of the Country field.
=IIf(IsNull([Region]),[City]&""& [PostalCode], [City]&" "&[Region]&"" &[PostalCode]) Displays the values of the City and PostalCode fields if Region is null; otherwise, it displays the values of the City, Region, and PostalCode fields.
Some examples of Is Null expressions.

When no data has been entered for a field, it is considered null.

If you attempt to perform calculations, run a totals query, or perform a sort on a field that contains some null values, you may not get the results you want. For example, the Average function automatically ignores fields containing null values.

Null values would also affect your results if you were counting the number of student records based on the Grade field, and some grades hadn't been recorded yet. The count would not reflect the total number of students because the students who didn't have grades yet would not be included.

You may want to exclude null values from your results, or possibly limit your results to just those records with null values. For example, you might want to search for students who didn't have grades yet.

You can do this by using the operators Is Null and Is Not Null. Simply type the operator in the query design grid in the Criteria cell for the field whose values you are checking.

You may also want to handle null values by using an expression and performing a different action on those records. You can use the built-in expression called Is Null. There are a few examples in the table at the left and the Quick Reference Card at the end of this course.

Some types of fields — the Text, Memo, and Hyperlink fields — can also contain a zero-length string, which means you know that no value exists for the field. For example, a student may have dropped out, so you know he doesn't have a grade.

You enter a zero-length string by typing two double quotation marks with no space between them ("").

Note     In an Access project that is connected to a Microsoft SQL Server™ database, you can enter a zero-length string in a field whose data type is varchar or nvarchar.

Page 20 of 23PREVNEXT