• + 0 comments
    DECLARE @lim int = 1000;
    DECLARE @counter int = 3;
    DECLARE @primes table(number int);
    INSERT INTO @primes VALUES (2)
    WHILE @counter <= @lim
        BEGIN
            if not exists (select top 1 1 from @primes where @counter % number = ``0)
                INSERT into @primes VALUES(@counter)
    		SET @counter = @counter + 2 -- only checking odd numbers
        END
    SELECT STRING_AGG(number,'&') FROM @primes;