Skip to main content
Version: v2.x

MS SQL Server: Filter Using Comparisons

Introduction

Comparison operators are used to compare values of the same type. For example, to compare two numbers, two strings, two dates, etc.

Equality operators (_eq, _neq)

The _eq (equal to) or the _neq (not equal to) operators are compatible with any MS SQL Server type (like Integer, Float, Double, Text, Boolean, Date/Time/Timestamp, etc.).

The following are examples of using the equality operators on different types.

Example: Integer (works with Double, Float, Int, etc.)

Fetch data about an author whose id (an integer field) is equal to 3:

GraphiQL
Query Variables
Request Headers
Documentation Explorer
No Schema Available

Example: String or Text

Fetch a list of authors with name (a text field) as "Sidney":

GraphiQL
Query Variables
Request Headers
Documentation Explorer
No Schema Available

Example: Boolean

Fetch a list of articles that have not been published (is_published is a boolean field):

GraphiQL
Query Variables
Request Headers
Documentation Explorer
No Schema Available

Example: Date (works with Time, Timezone, etc.)

Fetch a list of articles that were published on a certain date (published_on is a Date field):

GraphiQL
Query Variables
Request Headers
Documentation Explorer
No Schema Available

Greater than or less than operators (_gt, _lt, _gte, _lte)

The _gt (greater than), _lt (less than), _gte (greater than or equal to), _lte (less than or equal to) operators are compatible with any MS SQL Server type (like Integer, Float, Double, Text, Boolean, Date/Time/Timestamp, etc.).

The following are examples of using these operators on different types:

Example: Integer (works with Double, Float, etc.)

Fetch a list of articles rated 4 or more (rating is an integer field):

GraphiQL
Query Variables
Request Headers
Documentation Explorer
No Schema Available

Example: String or Text

Fetch a list of authors whose names begin with M or any letter that follows M (essentially, a filter based on a dictionary sort):

GraphiQL
Query Variables
Request Headers
Documentation Explorer
No Schema Available

Example: Date (works with Time, Timezone, etc.)

Fetch a list of articles that were published on or after date "01/01/2018":

GraphiQL
Query Variables
Request Headers
Documentation Explorer
No Schema Available

List based search operators (_in, _nin)

The _in (in a list) and _nin (not in list) operators are used to compare field values to a list of values. They are compatible with any MS SQL Server type (like Integer, Float, Double, Text, Boolean, Date/Time/Timestamp, etc.).

The following are examples of using these operators on different types:

Example: Integer (works with Double, Float, etc.)

Fetch a list of articles rated 1, 3 or 5:

GraphiQL
Query Variables
Request Headers
Documentation Explorer
No Schema Available

Example: String or Text

Fetch a list of those authors whose names are NOT part of a list:

GraphiQL
Query Variables
Request Headers
Documentation Explorer
No Schema Available

Filter or check for null values (_is_null)

Checking for null values can be achieved using the _is_null operator.

Example: Filter null values in a field

Fetch a list of articles that have a value in the published_on field:

GraphiQL
Query Variables
Request Headers
Documentation Explorer
No Schema Available