Access functions: list with examples

The functions you need most in Access queries on one page: nulls, conditions, text, numbers, dates, totals queries, domain functions and criteria. Each comes with an example you can run online straight away.

In short: functions look the same in the query design grid and in SQL view, for example IIf(UnitPrice > 10, "high", "low"). Text goes in quotes, field names with spaces in square brackets, and dates between hash signs as month/day/year.

All examples run on the Shop practice database with the tables Customers, Products, Categories, Orders and OrderDetails. Copy a line into Access SQL online and run it without installing Access. We ran every example in Access 2024 and compared the result with ours. You can download the database itself as an .accdb file from the database examples.

Jump to: Nulls and conditions, Text, Numbers, Dates, Totals queries, Domain functions, Criteria

Cheat sheet as a PDF

The cheat sheet is free as a printable PDF. All you need is a free account, no subscription and no payment details.

Create a free account and download the PDF Already have an account? Log in

Nulls and conditions

FunctionUseExample (SQL view)Lesson
Nzreplace Null with a substitute valueSELECT LastName, Nz(City, "unknown") AS Town FROM CustomersCalculated fields and IIf
IIfone of two values depending on a conditionSELECT ProductName, IIf(UnitsInStock < 10, "reorder", "ok") AS Status FROM ProductsCalculated fields and IIf
Switchvalue of the first condition that is trueSELECT ProductName, Switch(UnitPrice < 5, "low", UnitPrice < 20, "medium", True, "high") AS PriceBand FROM Products
Choosevalue by its position in a listSELECT OrderID, Choose(Weekday(OrderDate, 2), "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun") AS WeekDay FROM Orders
IsNulltests whether a value is NullSELECT OrderID, IsNull(ShippedDate) AS NotShipped FROM Orders

Text

FunctionUseExample (SQL view)Lesson
Leftthe first charactersSELECT LastName, Left(PostalCode, 2) AS Area FROM Customers
Rightthe last charactersSELECT LastName, Right(LastName, 2) AS Ending FROM Customers
Midcharacters from a positionSELECT LastName, Mid(LastName, 2, 3) AS Middle FROM Customers
Lennumber of charactersSELECT ProductName, Len(ProductName) AS Chars FROM Products
InStrposition where a text occurs (0 = not found)SELECT ProductName, InStr(ProductName, " ") AS Space FROM Products
Trimremove leading and trailing spacesSELECT Trim(" " & LastName & " ") AS Name FROM Customers
UCase, LCaseto upper or lower caseSELECT UCase(LastName) AS Upper, LCase(City) AS Lower FROM Customers
Replacereplace text with other textSELECT ProductName, Replace(ProductName, " ", "-") AS Slug FROM Products
StrConvconvert case, 3 = capitalise each wordSELECT StrConv(UCase(LastName), 3) AS Name FROM Customers
&join texts, Null becomes empty textSELECT FirstName & " " & LastName AS Name FROM CustomersCalculated fields and IIf
Formatnumber or date as text in a given formatSELECT OrderID, Format(OrderDate, "yyyy-mm") AS YearMonth FROM OrdersCrosstab query

Numbers

FunctionUseExample (SQL view)Lesson
Roundround to places, exactly .5 goes to the even numberSELECT ProductName, Round(UnitPrice * 0.9, 2) AS SalePrice FROM Products
Int, Fixinteger part (Int rounds down, Fix truncates)SELECT ProductName, Int(UnitPrice) AS Whole FROM Products
Absvalue without its signSELECT OrderID, Abs(OrderDate - ShippedDate) AS Days FROM Orders
Valnumber at the start of a textSELECT PostalCode, Val(PostalCode) AS Num FROM Customers
CCur, CDbl, CLng, CStrconvert to currency, double, long integer or textSELECT ProductName, CLng(UnitPrice) AS Rounded, CStr(UnitsInStock) AS AsText FROM Products
\, Modinteger division and remainderSELECT ProductName, UnitsInStock \ 12 AS Boxes, UnitsInStock Mod 12 AS Leftover FROM Products
Sqrsquare rootSELECT Sqr(Sum(Quantity)) AS Root FROM OrderDetails

Dates

FunctionUseExample (SQL view)Lesson
Date, Nowtoday's date, or with the time (fixed to 30 Nov 2026 in the exercises)SELECT OrderID FROM Orders WHERE OrderDate >= Date() - 30Dates and empty fields
Year, Month, Dayyear, month or day of a dateSELECT OrderID, Year(OrderDate) AS OrderYear, Month(OrderDate) AS OrderMonth FROM OrdersDates and empty fields
Weekdayday of the week as a number, with 2 as second argument Monday is 1SELECT OrderID, Weekday(OrderDate, 2) AS WeekDay FROM Orders
MonthNamename of the monthSELECT OrderID, MonthName(Month(OrderDate)) AS MonthName FROM Orders
DateDiffdifference between two dates in days ("d"), months ("m") or years ("yyyy")SELECT OrderID, DateDiff("d", OrderDate, ShippedDate) AS LeadTime FROM Orders
DateAddshift a date by days, months or yearsSELECT OrderID, DateAdd("m", 1, OrderDate) AS Reminder FROM Orders
DatePartpart of a date, such as the quarter ("q")SELECT OrderID, DatePart("q", OrderDate) AS Quarter FROM Orders
DateSerialdate from year, month and daySELECT OrderID FROM Orders WHERE OrderDate >= DateSerial(2026, 3, 1)
#…#date in SQL view, always month/day/yearSELECT OrderID FROM Orders WHERE OrderDate = #3/8/2026#Dates and empty fields

Totals queries

FunctionUseExample (SQL view)Lesson
SumsumSELECT OrderID, Sum(Quantity * SalePrice) AS OrderValue FROM OrderDetails GROUP BY OrderIDTotals query
Countnumber of values; Count(*) counts rows, Count(field) only non-Null valuesSELECT Count(*) AS AllOrders, Count(ShippedDate) AS Shipped FROM OrdersTotals query
AvgaverageSELECT CategoryID, Avg(UnitPrice) AS AvgPrice FROM Products GROUP BY CategoryIDTotals query
Min, Maxsmallest or largest valueSELECT CustomerID, Min(OrderDate) AS FirstOrder, Max(OrderDate) AS LastOrder FROM Orders GROUP BY CustomerIDTotals query
First, Lastvalue of the first or last row in the groupSELECT CustomerID, First(PaymentMethod) AS FirstPayment FROM Orders GROUP BY CustomerID
StDev, Varstandard deviation or variance of a sampleSELECT StDev(UnitPrice) AS Spread FROM Products

Domain functions

FunctionUseExample (SQL view)Lesson
DLookuplook up one value in a table or querySELECT OrderID, DLookup("LastName", "Customers", "CustomerID = " & CustomerID) AS Customer FROM OrdersDomain functions DLookup, DSum, DCount
DCountcount records that meet a conditionSELECT LastName, DCount("*", "Orders", "CustomerID = " & CustomerID) AS OrderCount FROM CustomersDomain functions DLookup, DSum, DCount
DSumsum over records that meet a conditionSELECT ProductName, DSum("Quantity", "OrderDetails", "ProductID = " & ProductID) AS UnitsSold FROM ProductsDomain functions DLookup, DSum, DCount
DAvg, DMin, DMaxaverage, smallest or largest value with a conditionSELECT ProductName, UnitPrice - DAvg("UnitPrice", "Products") AS Difference FROM ProductsDomain functions DLookup, DSum, DCount

Criteria

FunctionUseExample (SQL view)Lesson
Likepattern with * (any characters) and ? (one character)SELECT LastName FROM Customers WHERE LastName Like "W*"Wildcards with Like
Between … Andrange including both endsSELECT ProductName FROM Products WHERE UnitPrice Between 5 And 10Query criteria
Inone of several valuesSELECT LastName, City FROM Customers WHERE City In ("Bristol", "Boston")AND and OR in criteria
Is Nullfield is emptySELECT OrderID FROM Orders WHERE ShippedDate Is NullQuery criteria
Notreverse a conditionSELECT LastName FROM Customers WHERE Not RegularQuery criteria

Rules that always apply

  • Dates: In SQL view a date goes between hash signs and is always month/day/year: #3/8/2026# is 8 March 2026, whatever your regional settings say. In the design grid Access reads a date in your system format and converts it. More in the lesson date criteria.
  • Interval codes: DateDiff, DateAdd and DatePart take "d" (day), "ww" (week), "m" (month), "q" (quarter) and "yyyy" (year). "y" is day of the year, not year.
  • Null spreads: Any calculation with an empty field returns Null. & treats Null as empty text, + does not. Replace Null first with Nz, more in the lesson calculated fields.
  • Reserved words as column names: Access rejects AS Text, AS Date, AS Value or AS Order with "The SELECT statement includes a reserved word …". Choose another name or put it in square brackets: AS [Date].
  • Quotes: Access SQL accepts both "text" and 'text'. Wildcards in Like are * and ?, not % and _ as in other SQL dialects. More in the lesson SQL view.
  • Today in the exercises: Date() and Now() always return 30 Nov 2026 on this site so results stay the same. In Access it is the real current date.

How to learn the functions

A list is no substitute for practice. In the Access course you write these functions yourself, in the design grid and in SQL view, and the server checks your result with the visible data and with hidden data. That way you find out whether your query also works with other customers, prices and dates.

Write to us

Choose language

Select your preferred language