Holy ****!
That was awesome!

It took me waaaaay more time than I care to admit, but I got it.

I had to exclude 2 and 3 because of the use of FLOOR(SQRT(@P)) though.

There it is:

-------------------------------------------------
-- A little script to see how long it takes:
DECLARE @StartTime DATETIME
DECLARE @EndTime DATETIME
-- This is the start point. At the end we'll set the end point and calculate it
SET @StartTime = CURRENT_TIMESTAMP
-------------------------------------------------

/* Printing all prime numbers from 1 to 1,000 */

DECLARE @P INT                            --A variable to hold the number in check
DECLARE @counter INT                    -- A variable to hold the running numbers from 1 to @SQP
DECLARE @SQP INT                        -- the square root of @P (without the leftover)

SET @P = 1
SET @counter = 1

WHILE @P <= 1000                        --As long as @P <= 1000, do the following:
BEGIN
/* 1 */ SET @SQP = FLOOR(SQRT(@P))
/* 2 */ IF @P = 1
BEGIN
PRINT '1 is a special number. it''s neither Prime nor Composite Number'
END
/* 3 */ IF @P IN (2,3)
BEGIN
PRINT @P
END
ELSE           -- Now we're REALLY starting to check the number in @P
BEGIN
WHILE @counter <= @SQP
BEGIN
/* 1 */ IF @P % @counter = 0
BEGIN
/*    PRINT 'Not Prime' */
BREAK -- We can stop checking
END
ELSE
BEGIN
IF @counter = @SQP --That means it's a Prime
BEGIN
PRINT @P
BREAK -- We can stop checking
END
END
/* 2 */ IF @counter = @SQP
BEGIN
PRINT @P
BREAK -- We can stop checking
END
ELSE
BEGIN
SET @counter = @counter+1
END
END
END
/* 4 */BEGIN
SET @P = @P+1
SET @counter = 2
END
END
----------------------------------------
-- Calculating how long it took:
SET @EndTime = CURRENT_TIMESTAMP
PRINT ''
PRINT 'This process took '+ CAST(DateDiff(ms, @StartTime, @EndTime) AS VARCHAR) + ' milliseconds'
----------------------------------------