The EXISTS function returns a Boolean value to indicate whether a list contains at least one element (that is, whether the list exists).
If the list specified by ListExpression contains one or more elements, EXISTS returns TRUE. If the list contains no elements, EXISTS returns FALSE.
If you want to know only whether a list contains at least one elements or none, EXISTS executes more quickly than an expression involving the CARDINALITY function (for example, CARDINALITY(ListExpression ) <> 0).
A typical use of this function is to determine whether a field exists.
-- Determine whether the F1 array exists in the message. Note that the [ ]
-- are required
DECLARE Field1Exists BOOLEAN EXISTS(OutputRoot.XMLNS.Data.Source.F1[]);
-- Determine whether the F1 array contains an element with the value 'F12'.
-- Again note that the [ ] are required
DECLARE Field1F12Exists BOOLEAN
EXISTS(SELECT F.* FROM OutputRoot.XMLNS.Data.Source.F1[] AS F where F = 'F12');