This article is half-done without your Comment! *** Please share your thoughts via Comment ***
Check the below input data and expected output to split the given number and calculate addition between those numbers.
For example – Input number is 826 and result is 8+2+6=16.
Input Number:
1 |
826 |
Expected Result:
1 2 3 |
Result ----------- 16 |
Solution:
1 2 3 4 5 6 7 8 9 10 11 |
DECLARE @InputValue VARCHAR(10) = 826 DECLARE @i INT = 0 DECLARE @j INT = 0 WHILE @i <= LEN(@InputValue) BEGIN IF ISNUMERIC(SUBSTRING(@InputValue,@i,1)) = 1 SET @j = cast(SUBSTRING(@InputValue,@i,1) AS INT) + @j SET @i = @i + 1 END SELECT @j as Result |
Please try the different solution for this puzzle and share it via comment...