We will write a procedure that finds given number is Prime. The procedure gets an integer parameter and a bit parameter output. If the result parameter’s value is 0 (zero) then the written number is prime, if the result parameter’s value is 1 (one) then the written number is non-prime.

| Create Procedure sp_isPrime (@number int,@result bit output) as Begin Set @result = 1 Declare @i int = 2 While (@i<@number) Begin if(@number % @i = 0) Begin Set @result = 0 break End Set @i += 1 End return @result End |

After running the code above we will get succesfull message. Then we can use the procedure like below.

**Example 1**

| Declare @result bit Execute sp_isPrime 11,@result output Select @result |

**Result**: 1 (Prime)

**Example 2**

| Declare @result bit Execute sp_isPrime 9,@result output Select @result |

**Result**: 0 (non-Prime)

To See Other Stored Procedure Examples Click

__YOU MAY WANT TO SEE OUR ALL EXAMPLES PAGE, THEN CLICK HERE__

### Like this:

Like Loading...

*Related*