ARRAY Predicate

The Array (or Vector) predicate performs comparisons of two arrays using logical operators.

Syntax

Column_Reference Comparison_Operator [ ALL | SOME ] ARRAY [ Array_Elements ]

Elements

Column_Reference  Specifies the column name (alias). Its data type must be compatible with the format of the Array_Elements specified. A column reference can have multiple values, such as in a vector property or file attribute bitmask.
  
Comparison_Operator  Specifies the arithmetic operator to use to compare the Array_Elements. The Comparison_Operator can be any of the following:
  • Equals (=) and not equals (!=).
  • Greater than (>) and greater than or equals (=>).
  • Less than (<) and less than or equals (<=).
  
ALL | SOME  

Specifies how to quantify the Array_Elements. You can use either the ALL or SOME quantifier. If you specify ALL, each element on the left side of the expression is tested by using each element on the right side. If SOME is specified, at least one element on the left side is tested by using at least one element of the right side. For example, the following test fails because element 1 on the left side is less than element 2 on the right side.

[1,2,3] > ALL ARRAY [1,2]

The following test passes because element 2 on the left side is greater than element 2 on the right side (and element 3 on the left side is greater than elements 1 and 2 on the right side, but one passed test is sufficient).

[1,2,3] > SOME ARRAY [2,1]

If the ALL or SOME quantifier is absent, each element in the vector value on the left side of the operator is compared to its right-side counterpart at the same ordinal position. The test begins with the left-most elements and progresses left to right. A test passes if all the individual tests pass. For example, if vectors A[a1, a2, a3] and B[b1, b2, b3] are used, then:

A > B if and only if a1 > b1 , and  a2 > b2, and  a3 > b3

If the first m elements of the vector value on the right match the first m elements on the right side of the comparison operator, then comparisons actually begin with the (m+1)th elements where the values on the two sides differ. If all elements match, then comparison is determined by cardinality, and the one with the higher cardinality is considered greater. The following vector tests all pass:

ARRAY [2,3,4] > ARRAY [1,2]
ARRAY [2,3,4] > ARRAY [1,2,3]
ARRAY [2,3,4] > ARRAY [1,2,3,4]
ARRAY [2,3,4] > ARRAY [1,2,5]
ARRAY [2,3,4] > ARRAY [2,3,3]
ARRAY [2,3,4] > ARRAY [2,3]
ARRAY [2,3,4] < ARRAY [2,3,4,5]
ARRAY [2,3,4]!= ARRAY [2,3,4,5]

  
Array_Elements  

Specifies the elements in the array. You must include the square brackets when you specify the array elements.

Note: It is legal to have an empty array. For example:

SELECT foo FROM SCOPE() WHERE bar = ARRAY[]

Examples

  1. The following example finds all the compressed files with the archive bit set to ON.

    ...WHERE attrib = ARRAY [ 0X820 ]
  2. The following example finds the files with the archive bit set to ON or the compressed bit set to ON.

    ...WHERE attrib = SOME ARRAY [0X820 ]
  3. The following example finds ActiveX documents with a vectorprop value of [10,15,20].

    ...WHERE vectorprop = ARRAY [10, 15, 20]
  4. The following example finds ActiveX documents where at least one vectorprop value is 15.

    ...WHERE vectorprop = SOME ARRAY [15]
  5. The following example finds files that must be printed by printers named HP3 or HP4.

    ...WHERE printerprop = SOME ARRAY [ 'HP4' , 'HP3' ]

© 1997 by Microsoft Corporation. All rights reserved.