When using window functions with aggregation, you actually need to nest the results. Here is a version of your query that should work:
select a.ICode, MONTH(a.VDate), YEAR(a.vdate),
sum(isnull(a.qty, 0)),
sum(sum(isnull(a.qty, 0))) OVER (partition by a.icode order by a.icode) AS total
from t_Stock a
group by a.ICode, MONTH(a.VDate), YEAR(a.vdate)
order by a.icode, YEAR(a.vdate), MONTH(a.VDate);
I'm not sure what you intend to do with this. Having the order by
contain the same value as the partition by
is unusual. I would expect something like this:
select a.ICode, MONTH(a.VDate), YEAR(a.vdate),
sum(isnull(a.qty, 0)),
sum(sum(isnull(a.qty, 0))) OVER (partition by a.icode
order by year(a.vdate), month(a.vdate)
) AS total
from t_Stock a
group by a.ICode, MONTH(a.VDate), YEAR(a.vdate)
order by a.icode, YEAR(a.vdate), MONTH(a.VDate);