Hi @Shambhu Rai
Try this:
SELECT *,CAST((cons*1.0 / SUM(quantity)OVER(PARTITION BY SaleDateId ORDER BY SaleDateId RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW))AS decimal(10,2)) AS DEV_quantity
FROM main1
And for this issue :
done the casting part as well with cast(m.cons / c.NumberOfSameDay) as decimal(10,4) but result is changing and not coming as above
There is no need to convert the entire division algorithm into decimal, You just need to convert one of the divisors or dividends to decimal or float.Check the examples below:
SELECT 126/8 AS RESULT;
SELECT CAST(126/8 AS decimal(10,4)) AS RESULT;
SELECT CAST(126 AS float)/8 AS RESULT;--solution1
SELECT 126*1.0/8 AS RESULT;--solution2
SELECT CAST(126*1.0/8 AS decimal(10,2)) AS RESULT;
Best regards,
LiHong