You are viewing a single comment's thread. Return to all comments →
DECLARE @n INT = 1000; WITH numbers AS ( SELECT 2 AS num UNION ALL SELECT num + 1 FROM numbers WHERE num + 1 <= @n ) ,primes_num as ( SELECT * FROM numbers where not EXISTS (select * from numbers inners where numbers.num % inners.num=0 and numbers.num <> inners.num) ) select STRING_AGG(num,'&') from primes_num OPTION (MAXRECURSION 1000)
select STRING_AGG(num,'&') from primes
OPTION (MAXRECURSION 1000)
Seems like cookies are disabled on this browser, please enable them to open this website
Print Prime Numbers
You are viewing a single comment's thread. Return to all comments →
select STRING_AGG(num,'&') from primes
OPTION (MAXRECURSION 1000)