Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a problem in my query...
The query does not sum all the (qty)...even it have a value it outputs "0" value.

Heres the query:

SELECT 	`tblinventory`.`PK` AS `PK`,
	`tblinventory`.`prdct_ID` AS `ProductID`,
	`tblinventory`.`prdct_upc_barcode` AS `UPCBarcode`,
	`tblinventory`.`prdct_supp_ID` AS `SupplierID`,
	`tblinventory`.`prdct_supp` AS `SupplierName`,
	`tblinventory`.`prdct_ctgry_ID` AS `CategoryID`,
	`tblinventory`.`prdct_ctgry` AS `CategoryName`,
	`tblinventory`.`prdct_name` AS `ProductName`,
	`tblinventory`.`prdct_desc` AS `ProductDesc`,
	`tblinventory`.`lot` AS `ProductLot`,
	`tblinventory`.`unitcost` AS `UnitCost`,
	`tblinventory`.`packaging` AS `Package`,
	`tblinventory`.`exprtion_date` AS `Expiration`,
	`tblinventory`.`min_stck_level` AS `MinStckLvl`,
	`tblinventory`.`prdct_srp` AS `SRP`,
	`tblinventory`.`prdct_retail_price` AS `RP`,
	`tblinventory`.`qty` AS `QTY`,
IFNULL((SELECT SUM(tblwarehouse_prodcts.prod_qty) FROM tblwarehouse_prodcts WHERE (tblwarehouse_prodcts.prod_id=tblinventory.prdct_ID)),0) as W_Entry,
IFNULL((SELECT SUM(tblreplacement_prodcts.prod_qty) FROM tblreplacement_prodcts WHERE (tblreplacement_prodcts.prod_id=tblinventory.prdct_ID)),0) as W_Rplcmnt,
IFNULL((SELECT SUM(tbladjustment_prodcts.prod_qty) FROM tbladjustment_prodcts WHERE (tbladjustment_prodcts.prod_id=tblinventory.prdct_ID)),0) as W_Adjstmnt,
IFNULL((SELECT SUM(tbloutgoing_prodcts.prod_qty) FROM tbloutgoing_prodcts WHERE (tbloutgoing_prodcts.prod_id=tblinventory.prdct_ID)),0) as W_OTStck,
ifnull((
	(SELECT SUM(tblwarehouse_prodcts.prod_qty) FROM tblwarehouse_prodcts WHERE (tblwarehouse_prodcts.prod_id=tblinventory.prdct_ID)) + (SELECT SUM(tblreplacement_prodcts.prod_qty) FROM tblreplacement_prodcts WHERE (tblreplacement_prodcts.prod_id=tblinventory.prdct_ID)) -
	(SELECT SUM(tbladjustment_prodcts.prod_qty) FROM tbladjustment_prodcts WHERE (tbladjustment_prodcts.prod_id=tblinventory.prdct_ID)) - (SELECT SUM(tbloutgoing_prodcts.prod_qty) FROM tbloutgoing_prodcts WHERE (tbloutgoing_prodcts.prod_id=tblinventory.prdct_ID)
)),0) AS TOTALQTY
from tblinventory
GROUP BY prdct_ID



....can anyone help me?
Posted
Updated 21-May-10 19:25pm
v2
Comments
Sandeep Mewara 22-May-10 13:37pm    
SM: That was a good reason to vote down! What i said was a suggestion and not a resolution. You posted a full big query with a single statement that there is an output error, how would one know which one you are talking of? You did not added that, individually it was working fine. Yet, thanks for your precious vote!

1 solution

jleonorlane wrote:
SELECT SUM(tblwarehouse_prodcts.prod_qty) FROM tblwarehouse_prodcts WHERE (tblwarehouse_prodcts.prod_id=tblinventory.prdct_ID)


Have you tried executing them in a separate window and checked if they give correct results?

Look here:
IFNULL(expr1,expr2)[^] - The default result value of IFNULL(expr1,expr2) is the more “general” of the two expressions.

Troubleshoot whats wrong... start with a small query!
 
Share this answer
 
Comments
jleonorlane 22-May-10 9:23am    
Reason for my vote of 1 I have checked it & give correct results but my point is to get all what i have arrived result in first 3 IFNULL() clause...

SM: That was a good reason to vote down! What i said was a suggestion and not a resolution. You posted a full big query with a single statement that there is an output error, how would one know which one you are talking of? You did not added that, individually it was working fine. Yet, thanks for the vote!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900