Simulate an IF-WHILE EXISTS statement in a natively compiled module

Applies to: SQL Server Azure SQL Database

Natively compiled stored procedures do not support the EXISTS clause in conditional statements such as IF and WHILE.

The following example illustrates a workaround using a BIT variable with a SELECT statement to simulate an EXISTS clause:

DECLARE @exists BIT = 0;
SELECT TOP 1 @exists = 1 FROM MyTable WHERE ...;
IF @exists = 1;