WITH tabnum AS(
SELECT 0 AS number UNION ALL SELECT number+1 FROM tabnum WHERE number < 999)
SELECT ArmstrongNumber = number FROM tabnum
WHERE
number = POWER(COALESCE(SUBSTRING(cast(number AS VARCHAR(10)),1,1),0),3)
+ POWER(COALESCE(SUBSTRING(cast(number AS VARCHAR(10)),2,1),0),3)
+ POWER(COALESCE(SUBSTRING(cast(number AS VARCHAR(10)),3,1),0),3)
OPTION(MAXRECURSION 0)
Output:
No comments:
Post a Comment