In this program i am going to give you code how to write prime number in sql server 2008.
prime number divisible by itself and by one.that we call as prime number.
i have shown here using while and if loop to check whether given number is prime or not
ALTER procedure [dbo].[prime_number]
(@@val int)
as
begin
declare @int int;
set @int=2;
while(@int < @@val)
begin
if (@@val % @int=0)
begin
set @int=9;
break;
end
else
set @int=@int + 1;
end
if (@int=9)
begin
print 'number is not prime number'
end
else
print 'NUMBER is prime number'
end
prime number divisible by itself and by one.that we call as prime number.
i have shown here using while and if loop to check whether given number is prime or not
ALTER procedure [dbo].[prime_number]
(@@val int)
as
begin
declare @int int;
set @int=2;
while(@int < @@val)
begin
if (@@val % @int=0)
begin
set @int=9;
break;
end
else
set @int=@int + 1;
end
if (@int=9)
begin
print 'number is not prime number'
end
else
print 'NUMBER is prime number'
end
0 comments: