| title | Simulating IF-WHILE EXISTS - natively compiled module |
|---|---|
| ms.custom | seo-dt-2019 |
| ms.date | 03/01/2017 |
| ms.prod | sql |
| ms.prod_service | database-engine, sql-database |
| ms.reviewer | |
| ms.technology | in-memory-oltp |
| ms.topic | conceptual |
| ms.assetid | c0e187c1-cbd9-463c-b417-8a734574f102 |
| author | MightyPen |
| ms.author | genemi |
| monikerRange | =azuresqldb-current||>=sql-server-2016||=sqlallproducts-allversions||>=sql-server-linux-2017||=azuresqldb-mi-current |
[!INCLUDEappliesto-ss-asdb-xxxx-xxx-md]
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 Migration Issues for Natively Compiled Stored Procedures
Transact-SQL Constructs Not Supported by In-Memory OLTP