Example: Calling a .NET Framework Function

The following example shows a .NET Framework function being called within a query (WHERE clause).  It filters the orders in the Northwind Orders table so that only orders withing the last 6 years are displayed.

For the custom function, use the DateTime.Now() Visual Basic .NET function which returns the current time.  To display orders within the past 6 years, call the AddYears method with negative 6 as its parameter.  Convert this to a string format required by the SELECT statement using the ToString() directive.

DateTime.Now.AddYears(-6).ToString()

On the left-hand side of the clause, select the Order Date field in the Orders table.  The WHERE clause is:

Orders.OrderDate < DateTime.Now.AddYears(-6).ToString()

See Also

Calling Custom Code Functions in WHERE Clauses

Example: Calling a .NET Framework Function

Example: Calling a Custom Function in a Customizable Class