I have a stored procedure with a lot of calculation (one example below). Despite it does what intended I would like to have an easier, neat formula, something with a loop. Can anybody help, please
SET @result1 = CONVERT(decimal(6,2),(@a1*200000)/@v1); SET @result2 = CONVERT(decimal(6,2),((@a1+@a2)*200000)/(@v1+@v2)); SET @result3 = CONVERT(decimal(6,2),((@a1+@a2+@a3)*200000)/(@v1+@v2+@v3)); SET @result4 = CONVERT(decimal(6,2),((@a1+@a2+@a3+@a4)*200000)/(@v1+@v2+@v3+@v4)); SET @result5 = CONVERT(decimal(6,2),((@a1+@a2+@a3+@a4+@a5)*200000)/(@v1+@v2+@v3+@v4+@v5)); SET @result6 = CONVERT(decimal(6,2),((@a1+@a2+@a3+@a4+@a5+@a6)*200000)/(@v1+@v2+@v3+@v4+@v5+@v6)); SET @result7 = CONVERT(decimal(6,2),((@a1+@a2+@a3+@a4+@a5+@a6+@a7)*200000)/(@v1+@v2+@v3+@v4+@v5+@v6+@v7)); SET @result8 = CONVERT(decimal(6,2),((@a1+@a2+@a3+@a4+@a5+@a6+@a7+@a8)*200000)/(@v1+@v2+@v3+@v4+@v5+@v6+@v7+@v8)); SET @result9 = CONVERT(decimal(6,2),((@a1+@a2+@a3+@a4+@a5+@a6+@a7+@a8+@a9)*200000)/(@v1+@v2+@v3+@v4+@v5+@v6+@v7+@v8+@v9)); SET @result10 = CONVERT(decimal(6,2),((@a1+@a2+@a3+@a4+@a5+@a6+@a7+@a8+@a9+@a10)*200000)/(@v1+@v2+@v3+@v4+@v5+@v6+@v7+@v8+@v9+@v10)); SET @result11 = CONVERT(decimal(6,2),((@a1+@a2+@a3+@a4+@a5+@a6+@a7+@a8+@a9+@a10+@a11)*200000)/(@v1+@v2+@v3+@v4+@v5+@v6+@v7+@v8+@v9+@v10+@v11)); SET @result12 = CONVERT(decimal(6,2),((@a1+@a2+@a3+@a4+@a5+@a6+@a7+@a8+@a9+@a10+@a11+@a12)*200000)/(@v1+@v2+@v3+@v4+@v5+@v6+@v7+@v8+@v9+@v10+@v11+@v12));