K
KRISH
Hi! everybody,
Could anybody help me in solving the following prob.
I had three tables
[P_list] -fields are [PrID], [Pname]
[Store] - fields are [StoreID],[PrID],[Qnty],[RecvDt]
[StockOUT]- fields are [StoreID],[Qnty],[IssueDt]
Problem to solve: I want to find out current Stock available in store, which
should contain all products available in [store] table, even though they were
not issued.
I tried with the following query
SELECT store.prid, p_list.pname, p_list.ptype,
Sum(store.qnty)-nz(Sum(stockout.qnty)) AS curstock
FROM p_list INNER JOIN (store LEFT JOIN stockout ON store.storeid =
stockout.storeid) ON p_list.prid = store.prid
GROUP BY store.prid, p_list.pname, p_list.ptype;
Problem with the above query is
(i) if some product having [storeid] issued more than once in [stockout]
table then Sum(store.qnty) is giving result of sum of stock multiplied by no.
of times it is issued, which is absolutely wrong.
(ii) if i give [issuedt] criteria then my query is ignoing the products
which received but not issued.
Kindly let me know how to solve the problem. Any help is greatly appreciable.
Thanks a lot in advance.
Krish
Could anybody help me in solving the following prob.
I had three tables
[P_list] -fields are [PrID], [Pname]
[Store] - fields are [StoreID],[PrID],[Qnty],[RecvDt]
[StockOUT]- fields are [StoreID],[Qnty],[IssueDt]
Problem to solve: I want to find out current Stock available in store, which
should contain all products available in [store] table, even though they were
not issued.
I tried with the following query
SELECT store.prid, p_list.pname, p_list.ptype,
Sum(store.qnty)-nz(Sum(stockout.qnty)) AS curstock
FROM p_list INNER JOIN (store LEFT JOIN stockout ON store.storeid =
stockout.storeid) ON p_list.prid = store.prid
GROUP BY store.prid, p_list.pname, p_list.ptype;
Problem with the above query is
(i) if some product having [storeid] issued more than once in [stockout]
table then Sum(store.qnty) is giving result of sum of stock multiplied by no.
of times it is issued, which is absolutely wrong.
(ii) if i give [issuedt] criteria then my query is ignoing the products
which received but not issued.
Kindly let me know how to solve the problem. Any help is greatly appreciable.
Thanks a lot in advance.
Krish