如果有点毫无意义,这是一个有趣的运动.
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;