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
kamen4113121dSo you went to such lengths with SQL, but couldn't make a proper screenshot?
sergiolarosa891521121dIs 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-gud1566121dso... how fast is it?