Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
CREATE TABLE #OddNumbers (Number INT NOT NULL);
-- Populate with odd numbers >= 3
INSERT #OddNumbers (Number)
SELECT TOP (500000)
(ROW_NUMBER() OVER (ORDER BY t1.number) - 1) * 2 + 3 AS N2
FROM master..spt_values t1
CROSS JOIN master..spt_values t2;
-- Add a primary key
ALTER TABLE #OddNumbers ADD CONSTRAINT PK_Numbers PRIMARY KEY CLUSTERED (Number)
-- Select 2 as a special cae
SELECT 2 AS PrimeNumber
-- Select all numbers from #OddNumbers that do not have a divisor > 1 and < half the number being tested
SELECT testedNumber.Number AS PrimeNumber
FROM #OddNumbers testedNumber
LEFT JOIN #OddNumbers divisor
ON divisor.Number < (testedNumber.Number / 2) AND testedNumber.Number % divisor.Number = 0
GROUP BY testedNumber.Number
HAVING COUNT(divisor.Number) = 0;
DROP TABLE #OddNumbers
kamen364711dSo you went to such lengths with SQL, but couldn't make a proper screenshot?
Is this some type of new hobby?
I thought it was a useful exercise to make sure my brain hasn't been turned into mush by all the dev ops stuff I've been working on recently
git-gud157711dso... how fast is it?
Your Job Suck?
Take a quick quiz from Triplebyte to skip the job search hassles and jump to final interviews at hot tech firms
Get a Better Job