Comparison Predicate

The comparison predicate uses arithmetic operators to compare column data to a literal value. For a row to be selected, the predicate must evaluate to TRUE. (Index Server queries that use such predicates are called relational property queries.)

Syntax

Column_Reference Arithmetic_Operator Literal [ Boolean_Operator Column_Reference Arithmetic_Operator Literal ... ]

Elements

Column_Reference  Specifies the column name (alias). Its data type must be compatible with the format of the literal specified.
  
Arithmetic_Operator  

Specifies the arithmetic operator to use to compare the column reference data to a literal value. The following table lists the operators with examples.

Operator Symbol Example
Equals = WHERE DocAuthor = 'Isaac Asimov'
Not equals != or <> WHERE DocTitle != 'Finance'
Less than < WHERE WordCount < 1000
Greater than > WHERE WordCount > 500
Less than or equal to <= WHERE WordCount <= 500
Greater than or equal to >= WHERE WordCount >= 500
  
Literal  

Specifies a constant data value that complies with the constraints of its data type. The following literal types are supported:

Basic String

The basic string literal can be an ANSI string constant, or a Unicode string constant. Since strings are surrounded by single quotes, to specify a quote character as part of the string, use two single quotes. An empty string is denoted by ''. Examples:

'One Fine Day'
'Rosemary''s Baby'
 

Exact Numeric

An exact numeric literal can be an integer or a number with a decimal point. When an exact numeric literal is an integer, it can be one, two, four, or eight bytes in size. Examples:

-300              (2 byte integer)
67000           (4 byte integer)
5000000000 (8 byte integer)
.55
-366.12
 

Approximate Numeric

An approximate numeric literal is composed of a mantissa and a signed or unsigned exponent. Examples:

2.5 E-5
-.5E20
 

Hexadecimal

A hexadecimal literal is an integer expressed in hexadecimal notation. The hexadecimal expression has to be prefixed with "0x". Example:

0x2F456
 

Boolean

A boolean literal can only have the values TRUE or FALSE.
 

Absolute Date/Time

The absolute date/time literal can be expressed as a date string or as a timestamp string. Note that the "/" (slash) and the "-" (dash) are interchangeable.

Examples:

'1996/01/25'
'1996/01/25 02:05:00'
'1996-02-28 10:59:03'
Note: The Index Server engine requires dates to be in terms of file times based on Greenwich Mean Time (GMT).
 

Relative Date/Time

The relative date/time literal expresses a date relative to the current date.

The syntax for the DATEADD() function is:

DATEADD( Time,  Relative_Interval,
{ Relative_Date/Time | GETGMTDATE()) }
Time has the following values:
  • year or yy
  • quarter or qq
  • month or mm
  • day or dd
  • week or wk
  • hour or hh
  • minute or mi
  • second or ss

The GETGMTDATE() function is modelled after the GETDATE() function in SQL Server, but GETGMTDATE() indicates the current Greenwich Mean Time rather than the current time on the local machine.

Use the following format to specify the relative date/time:

For example, to express an Index Server relative time value of -2 years, enter:

DATEADD(year, -2, GETGMTDATE())
To express a relative time value of - 3 years, 24 days, and 5 hours, enter:
DATEADD(hh, -5, DATEADD(dd, -24, DATEADD(yy, -3, GETGMTDATE())))
Note: Positive (future) dates are not supported. The Index Server engine requires dates to be in terms of file times based on Greenwich Mean Time (GMT).
 

NULL

A NULL literal is an undefined literal.

Note: When determining if a literal is defined or not, use IS and IS NOT instead of the equals operator ( = ).
 

  
Boolean_Operator  Specifies the boolean operator to use, following the precedence rules previously stated, that combines the comparison predicates.

Examples

  1. The following example returns all the files that have the phrase Financial Data as the title of their document.

    ...WHERE DocTitle = 'Financial Data'
  2. The following example returns all the files that have the phrase Financial Data as the title of their document or that have John James as the author.

    ...WHERE DocTitle = 'Financial Data' 
       OR DocAuthor = 'John James'
  3. The following example returns all the files that have a size less than 10,0000 or a word count less than or equal to 800.

    ...WHERE size < 10000
       OR DocWordCount <= 800

  4. © 1997 by Microsoft Corporation. All rights reserved.