DECLARE @Number INT = 123456789
;WITH getDigitsCTE AS (
SELECT
SlNo = 1
, Quotient = @Number / 10
,Remainder = @Number % 10
UNION ALL
SELECT
SlNo = SlNo + 1
,Quotient / 10
, Quotient % 10
FROM getDigitsCTE
WHERE Quotient > 0
)
SELECT
SUMOfODDNumbers = SUM(Remainder)
FROM getDigitsCTE
WHERE Remainder %2 <> 0
/*
SUMOfODDNumbers
---------------
25
*/