Home Forums SQL Server 7,2000 T-SQL Creating Stored Procedure in SQL server 2000 for Printing Prime Numbers RE: Creating Stored Procedure in SQL server 2000 for Printing Prime Numbers

  • And, to make it a bit faster, let's skip all of the even numbers after 2 (I suspect I've chosen a less than desirable way to do that)

    DECLARE

    @i INT,

    @a INT,

    @count INT

    SET @i = 1

    WHILE (@i <= 500)

    BEGIN

    SET @count = 0

    SET @a = 1

    WHILE (@a <= @i)

    BEGIN

    IF (@i % @a = 0)

    SET @count = @count + 1

    SET @a = @a + 1

    END

    IF (@count = 2)

    PRINT @i

    SET @i = @i + case when @i < 3 then 1 else 2 end

    END