4
Item         ItemName        PackageID  Specifics    brandname  GRNQty  UnitPric GRNValue
102814742801 ALL BRAN FLAKES 1PKT       Bran.        KELLOGS    7       15.9    111.3
102814742801 ALL BRAN FLAKES 1PKT                    KELLOGS    50      15.9    795
100314860301 ALMOND FLAKED   1PKT       Alm.         HYSON      20      52      1040
100314860301 ALMOND FLAKED   1PKT                    HYSON      30      52      1560
101814899665 ALMONDS ROASTED 1KG                     HOMELINE   250     59.5    14875
101426707397 ANCHOVY FILLETS 1TIN       Anch.        VARIOUS    4       34      136
101426707397 ANCHOVY FILLETS 1TIN                    VARIOUS    8       34      272

I'd like to get the sum of a particular Item in the column. I want to do Sum of GRNQty as well as GRNValue of Same Type Item in the table.

2

Particular Item

SELECT SUM(GRNQty) GRNQtySum,SUM(GRNValue) GRNValueSum
FROM mytable WHERE Item = '102814742801';

All Items By Item

SELECT Item,SUM(GRNQty) GRNQtySum,SUM(GRNValue) GRNValueSum
FROM mytable GROUP BY Item;

All Items By PackageID

SELECT PackageID,SUM(GRNQty) GRNQtySum,SUM(GRNValue) GRNValueSum
FROM mytable GROUP BY PackageID;

All Items By brandname

SELECT brandname,SUM(GRNQty) GRNQtySum,SUM(GRNValue) GRNValueSum
FROM mytable GROUP BY brandname;
-1

You could use a computed column in a view or in your select statement.

SELECT *, GRNQty + GRNValue AS Sum 
FROM tableName 
WHERE Item=@id

Not the answer you're looking for? Browse other questions tagged or ask your own question.