Prime Number Checking Procedure in SQL Server
Hello everyone,
In this article, I will give information about the prime number checking procedure in SQL Server.
You can constantly improve yourself by making such examples in SQL Server.
You can easily do this with the help of the code below.
CREATE PROC IsNumberPrime @Number INT
AS
DECLARE @Counter INT;
SET @Counter = 2;
BEGIN
WHILE (@Counter) < @Number
BEGIN
IF (@Number % @Counter = 0)
BEGIN
SELECT 'Not Prime';
RETURN;
END;
SET @Counter = @Counter + 1;
END;
SELECT 'Prime';
RETURN;
END;
--Kullanımı
EXEC dbo.IsNumberPrime @Number = 20;
EXEC dbo.IsNumberPrime @Number = 23;
When you create the procedure and run the code, you will get a result like the one below.
As you can see, the prime number checking procedure has been created.
Good luck to everyone in business and life.