• + 0 comments

    declare @PrimeNumCnt Int = 1, @PrimeNumUpTo int = 1000, @PrimeNumList nvarchar(4000); while @PrimeNumCnt <= @PrimeNumUpTo begin declare @IsPrime int = 0 Declare @N int = 1 while @N <= @PrimeNumCnt begin set @IsPrime = @IsPrime + (select case when @PrimeNumCnt <> @N and @PrimeNumCnt % @N = 0 then 1 else 0 end) if @IsPrime = 0 begin break end set @N = @N+1 end --select @PrimeNumCnt,@IsPrime if @IsPrime = 1 begin set @PrimeNumList = (select concat(@PrimeNumList,'&',@PrimeNumCnt)) end set @PrimeNumCnt = @PrimeNumCnt+1 end select right(@PrimeNumList,len(@PrimeNumList)-1);