| Author |
Topic |
|
Villanuev
Constraint Violating Yak Guru
478 Posts |
Posted - 2011-12-16 : 02:39:29
|
| Guys,Here is my requirements.I need only to display records with positive qty.what should i place to my condition in my scriptget my requirements. requirements.Sample data.TABLE1ItemID--Qty--Value--------------------111111-- 14---32.00111111-- -14---32.00--------------------222222-- 20---40.00222222-- 15---40.00Result:TABLE1ItemID--Qty--Value-------------------222222-- 35---80.00Select Itemd, SUM(qty) as Qty, ??"I would like to display the positive value of (SUM(QTY) " SUM(value)From table1??What condition should be add into this partThanks.JOV |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-16 : 03:12:32
|
| [code]Select Itemd,SUM(qty) as Qty, SUM(value) as valueFrom table1GROUP BY ItemdHAVING SUM(qty) >0[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Villanuev
Constraint Violating Yak Guru
478 Posts |
Posted - 2011-12-16 : 03:37:44
|
| Thanks visakh.. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-16 : 06:23:36
|
| wc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Villanuev
Constraint Violating Yak Guru
478 Posts |
Posted - 2011-12-19 : 03:49:01
|
| Hi Visakh,I have 3 tables, but when i check the records i have no records in i.INVENTSUM but i found records from it.INVETTABLE & loc.INVETDIM. My concerned is why I still capture the data even the value of "having sum(i.PHYSICALINVENT) > 0" i think this condition is not satisfy. I notice also that even the i.PHYSICALINVENT is 0 the sum(i.PHYSICALINVENT) as Qty has display value. 1.i.INVENTSUM ---2.it.INVENTTABLE ---3.loc.INVENTDIM---select it.ASUMODEL, left(it.itemid,7) as ItemID, it.ITEMNAME, it.ITEMID as SKU, sum(i.PHYSICALINVENT) as Qty, sum(i.POSTEDVALUE) as InventoryValue, ITEMGROUPID, loc.WMSLOCATIONID, loc.INVENTLOCATIONID, i.INVENTDIMIDfrom INVENTSUM iinner join INVENTTABLE it on i.itemid = it.itemid and it.dataareaid = 'red' -- and sum(i.PHYSICALINVENT) > 0inner join INVENTDIM loc on loc.INVENTDIMID = i.INVENTDIMID and loc.dataareaid = i.dataareaidwhere i.dataareaid in ('blue') and it.ASUMODEL in ('Cosmos') and it.ITEMGROUPID not in ('Scrap')group by it.ASUMODEL, it.ITEMNAME, it.ITEMID, left(it.itemid,7), it.ITEMGROUPID, loc.WMSLOCATIONID, loc.INVENTLOCATIONID, i.INVENTDIMIDHaving sum(i.PHYSICALINVENT) > 0 order by it.ASUMODEL, it.ITEMIDRegards,JOV |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-19 : 04:29:19
|
| please post some sample data to explain your problem. Cant make out what exactly is problem you're facing from the decsription above.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Villanuev
Constraint Violating Yak Guru
478 Posts |
Posted - 2011-12-19 : 04:45:52
|
| Here is Sample Table & DataInventtableItemID--DataareaID--Model---------------------------LGE2257----red------VX10000 LGE2212----red------VX10000 LGE2260----red------VX900InventsumItemid--Postedvalue-PhysicalInvent-Invetdimid--Dataareaid---------------------------------------------------------LGE2257- 140.00---- 14.00------DIM0000725 ----blue LGE2257- -139.43---- -14.00------DIM0017562 ----blueLGE2260- 100.00---- 45.00------DIM0012345 ----blue this is negative 14 and negative 139.43 Inventdim----------------------------------------Inventdimid--WMSlocationid--Dataaeraid------------------------------------------DIM0000725 -- TRC-dock ----blue--------DIM0017562 -- TRC-dock ----blue--------DIM0012345 -- Parts ----blue--------1. when I sum up the Physicalinvent to value should be 0 but somtimes it appears 14.002. there is records in inventtable but no records both from inventsum and invetdim but it appears in the query.3. if the value of sum(PhysicalInvent) is zero this sould not be in the query result.the result should be the LGE2260..the other itemid is not included. Thanks.JOV |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-19 : 05:13:12
|
what you're telling doesnt make sense with query postedyou're using inner join with inventsum and invetdim so under no condition it will return records in inventtable but no records both from inventsum and invetdim which contradicts what you're specifying in point 2 aboveif the value of sum(PhysicalInvent) is zero this sould not be in the query result - again you've already incuded the condition in your HAVING as below...group by it.ASUMODEL,it.ITEMNAME,it.ITEMID,left(it.itemid,7),it.ITEMGROUPID,loc.WMSLOCATIONID,loc.INVENTLOCATIONID,i.INVENTDIMIDHaving sum(i.PHYSICALINVENT) > 0 .. so unless you've multiple locations per invent table entry this should also work fine.I'm sure you're either missing something or are using some other query of which above forms just a part and might not have given us full picture to understand real problem.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Villanuev
Constraint Violating Yak Guru
478 Posts |
Posted - 2011-12-19 : 21:38:01
|
| Hi Visakh, I need to check thoroughly the records then i will post the problem. Thanks. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|