select t2.VoucherNumber as Invoice_Number, i.ItemName as Item_Name, Sum(t2.Aqty) as Qty
from Item i, Party p, Tran1 t1, VTran2 t2, Cases c, VoucherTypes VT
Where t1.LorryNo='22-8205' and t1.VoucherType=VT.VoucherType and VT.ActualVoucherType='sales'
and t1.VoucherNumber=t2.VoucherNumber and t2.ItemName=i.Itemname and
t2.ItemName=c.ItemName and t1.LoadingStatus='2'
GROUP BY t2.VoucherNumber, i.ItemName
and
select i.ItemName as Item_Name, Sum(t2.Aqty) as Qty
from Item i, Party p, Tran1 t1, VTran2 t2, Cases c, VoucherTypes VT
Where t1.LorryNo='22-8205' and t1.VoucherType=VT.VoucherType and VT.ActualVoucherType='sales'
and t1.VoucherNumber=t2.VoucherNumber and t2.ItemName=i.Itemname and
t2.ItemName=c.ItemName and t1.LoadingStatus='2'
GROUP BY i.ItemName
few references :
Get Ready to Learn SQL Server: 6 – Group and Summarize Your Results[
^]
http://www.w3schools.com/sql/sql_groupby.asp[
^]
http://www.w3schools.com/sql/sql_func_sum.asp[
^]