I am trying to write the given SQL code into MS SQL SERVER for listing Prime numbers From 2 to 100, as 2&3&5&7….&97.
DECLARE @i INT
SET @i = 2
DECLARE @r VARCHAR(500)
SET @r = ""
WHILE (@i <=100)
BEGIN
DECLARE @j INT
SET @j = FLOOR(SQRT(@i))
WHILE @j > 1
BEGIN
IF ( @i % @j =0 ) AND ( @i != @j ) AND ( @j != 1 )
BEGIN
-- Do nothing, just continue the loop
END
ELSE
BEGIN
SET @r = CONCAT( @r , @i , "&" )
BREAK
END
SET @j = @j - 1
END
SET @i = @i + 1
END
PRINT @r
Please correct the syntax error, I am getting in given SQL Code.