La funzione EXISTS restituisce un valore BOOLEAN che indica se un elenco contiene almeno un elemento (ossia, se l'elenco esiste).
Se l'elenco specificato da ListExpression contiene uno o più elementi, EXISTS restituisce TRUE. Se l'elenco non contiene elementi, EXISTS restituisce FALSE.
Se si desidera solo sapere se un elenco contiene o meno elementi, EXISTS viene eseguita più rapidamente di un'espressione che utilizza la funzione CARDINALITY (ad esempio, CARDINALITY(ListExpression ) <> 0).
Un utilizzo comune di questa funzione è quello di determinare se un campo esiste.
-- Determine whether the F1 array exists in the message. Note that the [ ] -- are required DECLARE Field1Exists BOOLEAN EXISTS(OutputRoot.XML.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.XML.Data.Source.F1[] AS F where F = 'F12');