• + 0 comments
    /*
    Enter your query here.
    Please append a semicolon ";" at the end of the query and enter your query in a single line to avoid error.
    */
    
    DECLARE @l INT = 1000
    
    DECLARE @n INT = 2
    
    DECLARE @primes VARCHAR(MAX) = ''
    
    WHILE @n <= @l
    BEGIN
        
        DECLARE @d INT = 2
        DECLARE @b BIT = 1
        
        WHILE @d < @n
        BEGIN
            
            IF @n % @d = 0 AND @n <> @d
            BEGIN
                SET @b = 0
                BREAK;
            END
            
            SET @d = @d + 1
        END
        
        IF @b = 1 
        BEGIN
            SET @primes = @primes + '&' + CAST(@n as VARCHAR(MAX))
        END
    
        SET @n = @n + 1
    END
    
    SET @primes = SUBSTRING(@primes, 2, LEN(@primes) - 1)
    
    print @primes