Es un ejercicio divertido aunque un poco inútil.
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;
Es un ejercicio divertido aunque un poco inútil.
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;