Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Requirement :

To drift after every stock count how many and which EPCs were corrected by the stock count

1)Were in that same location in the before count snapshot(At 5:30 AM and before 11:30 AM)

2)Were in different location

3)Weren't in a location at all

4)% of the above

Tables created :

DRIFT_ITEMS_Pre (Before movement EPC Details will be stored int his table)

TPNB

EPC

LOCATIONID

ITEMSTATUS

LOADED_TIME

MOVED_FLAG

DRIFT_ITEMS_POST(After movement EPC Details will be stored int his table)
TPNB
EPC

LOCATIONID

ITEMSTATUS

LOADED_TIME

MOVED_FLAG

Also there is another table where we will capture the log parcer details of each EPC and loadtime.

My current approach is to create two views along with an aggregate procedure , then will create one parent view which will generate the report like below however i am getting some errors:

1) One procedure/Update/Merger will run first as follows:

update DRIFT_ITEMS DIPre,DRIFT_ITEMS_POST DIPost SET MOVED_FLAG='1'
where EPC IN(Select EPC from Drift_EPC_Items DIP where
(((DIPre.LOADED_TIME>DIP.TIME_STAMP)>STOCK.stockcounts.STARTDATE) )
OR
((STOCK.stockcounts.FINISHDATE>DIP.TIME_STAMP)>DIPost.LOADED_TIME ))

ERROR :

Error starting at line 1 in command:
update DRIFT_ITEMS DIPre,DRIFT_ITEMS_POST DIPost SET MOVED_FLAG='1'
where EPC IN(Select EPC from Drift_EPC_Items DIP where
(((DIPre.LOADED_TIME>DIP.TIME_STAMP)>STOCK.stockcounts.STARTDATE) )
OR
((STOCK.stockcounts.FINISHDATE>DIP.TIME_STAMP)>DIPost.LOADED_TIME ))
Error at Command Line:1 Column:25
Error report:
SQL Error: ORA-00971: missing SET keyword
00971. 00000 - "missing SET keyword"
*Cause:
2)View Creation in order to achieve below criterias
a)Were in that same location in the before count snapshot(At 5:30 AM and before 11:30 AM)

b)Were in different location

c)Weren't in a location at all

d)% of the above


CREATE OR REPLACE FORCE VIEW "DRIFT_COUNTS_MOVEMENTS_VW" ( "EPC", "LOCATIONID") AS
SELECT s.locationid, p.locationid,
count(epc) FROM DRIFT_ITEMS s inner join drift_items_post p
on (s.epc=p.epc and s.moved_flag <> 1 and s.locationid <> p.locationid )
group by s.locationid;
3)View Creation
a)Were in that same location in the before count snapshot(At 5:30 AM and before 11:30 AM)

b)Were in different location

c)Weren't in a location at all

d)% of the above


CREATE OR REPLACE FORCE VIEW "REPORT"."DRIFT_MOVEMENTS_POST_VW" ( "LOCATIONID","EPC") AS
SELECT p.locationid,count(epc)
FROM DRIFT_ITEMS_POST p where epc not in (select epc from drift_items s where s.moved_flag <> 1) group by p.locationid;

in 2nd view creation also i am getting error(view is getting created with error).Can anyone plz help to sort this out or suggest me some best approach to achieve the requirement.
Posted

1 solution

First of all, why store the data in two separate tables if the only difference is the status of the row (before movement / after movement). This causes extra complexity

However, if you want to use those table and if I understand the question correctly, to update the pre table could be something like:
SQL
UPDATE DRIFT_ITEMS_Pre
SET MOVED FLAG = '1'
WHERE EXISTS (SELECT 1
              FROM  DRIFT_ITEMS_POST
              WHERE DRIFT_ITEMS_POST.EPC = DRIFT_ITEMS_Pre.EPC)

AND MOVED FLAG != '1';
IN other words if EPC is found in the post movement table

Then again the other table based on the idea the location id has changed later perhaps something like
SQL
UPDATE DRIFT_ITEMS_POST a
SET MOVED FLAG = '1'
WHERE EXISTS (SELECT 1
              FROM  DRIFT_ITEMS_POST b
              WHERE a.EPC = b.EPC
              AND   a.LOCATIONID != b.LOCATIONID
              AND   a.LOADED_TIME < b.LOADED_TIME)
AND MOVED FLAG != '1';


I'm not sure about the logic since you didn't explain the details and usage of each field. However, I'm sure you get the idea from those examples.
 
Share this answer
 

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