Filtering & Options

Use OData query options to filter, sort, page, and shape the data returned by the MVP One API.

OData is an open standard for accessing data over HTTP. It lets you query data through URLs in a way that is similar to SQL.

Main OData Features

FeatureSQL ExampleOData Example
Querying specific table columnsSELECT ENAME, JOB, SAL FROM People/People?$select=ENAME,JOB,SAL
Querying the second 5 recordsSELECT * FROM Accounts ORDER BY (SELECT NULL)
OFFSET 5 ROWS FETCH FIRST 5 ROWS ONLY
/Accounts?$top=5&$skip=5
Ordering dataSELECT * FROM WorkOrders ORDER BY ActualStartDate DESC, SAL/WorkOrders?$orderby=ActualStartDate desc,SAL
Querying joined tablesSELECT * FROM Dept LEFT OUTER JOIN Accounts ON Dept.DEPTNO = Accounts.DEPTNO/Depts?$expand=Accounts
Filtering dataSELECT * FROM PurchaseOrders WHERE (SAL/2 > 500 AND OrderedDate <= '01/01/1985') OR (COMM IS NOT NULL AND ENAME LIKE 'J%')/PurchaseOrders?$filter=(SAL div 2 gt 500 and OrderedDate le 1985-01-01) or (COMM ne null and startswith(ENAME,'J'))
Aggregating dataSELECT SUM(SAL) AS Sum, MAX(SAL) AS Max, MIN(SAL) AS Min, AVG(SAL) AS Avg FROM PartStockReplenishment/PartStockReplenishment?$apply=aggregate(SAL with sum as Sum,SAL with max as Max,SAL with min as Min,SAL with average as Avg)

Filter Expressions

Use the $filter query option to apply mathematical, logical, and string-based filtering. OData operators and functions are case-sensitive.

Sample URL

/Emps?$filter=(SAL div 2 gt 500 and HIREDATE le 1985-01-01) or (COMM ne null and startswith(ENAME,'J'))

Operations

SQLOData
=eq
!=ne
>gt
>=ge
<lt
<=le
ANDand
ORor
NOTnot
+add
-sub
*mul
/div
%mod
()()
IS NULLeq null
IS NOT NULLne null
X LIKE '%Y%'substringof('Y',X) in OData v1-v3
contains(X,'Y') in OData v4
X LIKE 'Y%'startswith(X,'Y')
X LIKE '%Y'endswith(X,'Y')

String Functions

SQLOData
LEN(X)length(X)
CHARINDEX(X,'Y')indexof(X,'Y')
REPLACE(X,'Y','Z')replace(X,'Y','Z')
SUBSTRING(X,2,3)substring(X,2,3)
LOWER(X)tolower(X)
UPPER(X)toupper(X)
TRIM(X)trim(X)
CONCAT(X,Y)concat(X,Y)

Date Functions

SQLOData
DATEPART(year,X)year(X)
DATEPART(month,X)month(X)
DATEPART(day,X)day(X)
DATEPART(hour,X)hour(X)
DATEPART(minute,X)minute(X)
DATEPART(second,X)second(X)

Mathematical Functions

SQLOData
ROUND(X)round(X)
FLOOR(X)floor(X)
CEILING(X)ceiling(X)