MS Access Val() Function
The Val()
function in MS Access extracts numeric values from a string. This is useful for cleaning up data that might have mixed text and numbers, or for extracting numerical components from text strings.
Val(): Definition and Usage
Val()
attempts to convert a string into a number. It reads the string character by character until it encounters a non-numeric character. At that point, it stops reading and returns the number it has parsed so far. If the string starts with non-numeric characters, it returns 0. If the string is `NULL`, it returns `NULL`.
Syntax
Syntax
Val(string)
Parameter Values
Parameter | Description |
---|---|
string |
The string expression containing the number to extract. This is required. |
Example
Extracting Numbers from a String
This example extracts the numeric part from the 'PostalCode' column in the 'Customers' table (assuming a 'Customers' table exists with a 'PostalCode' column containing strings that might include non-numeric characters).
Syntax
SELECT Val(PostalCode) FROM Customers;
Output
(The numeric portion of each PostalCode from the Customers table will be displayed here. If a PostalCode starts with non-numeric characters, 0 will be returned. If a PostalCode is NULL, NULL will be returned.)