少し無意味なら楽しい運動です。
DECLARE @var1 int = 12345;
WITH i AS (
SELECT @var1 / 10 n, @var1 % 10 d
UNION ALL
SELECT n / 10, n % 10
FROM i
WHERE n > 0
)
SELECT SUM(d)
FROM i;
少し無意味なら楽しい運動です。
DECLARE @var1 int = 12345;
WITH i AS (
SELECT @var1 / 10 n, @var1 % 10 d
UNION ALL
SELECT n / 10, n % 10
FROM i
WHERE n > 0
)
SELECT SUM(d)
FROM i;