Skip to content

Latest commit

 

History

History
30 lines (24 loc) · 1.24 KB

File metadata and controls

30 lines (24 loc) · 1.24 KB
title Simulating IF-WHILE EXISTS - natively compiled module
description Learn how to simulate the EXISTS clause in conditional statements, which is not supported by natively compiled stored procedures in SQL Server.
author MikeRayMSFT
ms.author mikeray
ms.reviewer randolphwest
ms.date 01/12/2024
ms.service sql
ms.subservice in-memory-oltp
ms.topic conceptual
monikerRange =azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current

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

[!INCLUDE 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;

Related content