What are Domain Functions?Domain Functions are some inbuilt functions that can access the Data in Tables. In simple terms Domain functions are simplified Queries. If you are ever in a position to need to Count the number of Customer in the table who has their first name as 'Paul', you start typing..
SELECT Count(FirstName) As CountOfFirstName
WHERE FirstName = 'Paul';
So if you are someone who is very lazy (like me !) or you have very limited knowledge of writing Queries or even if you think writing Queries is a bore, then you are in luck. Someone thought to just do this is a simpler way, just tell the compiler what you need, where to look and it gives you a result. That is the discovery of the Domain functions.
Identifying & understanding a Domain functionIn general Domain functions start with the letter 'D'. There are about 8 Domain functions.
- SELECT Domain functions
- AGGREGATE Domain functions
Things to know !
- All parameters are treated as Strings. So make sure you enclose them in Double Quotes.
- A Domain function can return only one Value even if the records returned are more than one.
- A Domain function can return a Null value, if the condition is not met. So be prepared to capture that scenario.
- Domain functions can be heavy, so best to limit its usage.
- The criteria should be evaluated to a String, based on the Data type of the field the condition would vary. Look at the common usage syntax for more information.
Anatomy of a Domain function
- expression - the field name where the function needs to look at
- domain - name of the table/query where the function needs to be applied
- criteria - (Optional) if you are looking for something in specific, then you add it here.
DFunctionName("expression", "domain", "criteria")
For the example we are dealing with, the function we would use be Count.
DCount("*", "Customers", "FirstName = 'Paul'")
If you have seen the above example, I have used the * as the Column/Field name, this is because, specifying a particular column in a Count function would slow down the compiler. To be efficient using a * would be faster.