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.

Prime Number Checking Procedure in SQL Server

As you can see, the prime number checking procedure has been created.

Good luck to everyone in business and life.

173 Views

Yavuz Selim Kart

I try to explain what I know in software and database. I am still improving myself by doing research on many programming languages. Apart from these, I am also interested in Graphic Design and Wordpress. I also have knowledge about SEO and Social media management. In short, I am a determined person who likes to work hard.

You may also like...

Don`t copy text!