Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Fact Table:
Order# | Amount | OrderStatus |
---|---|---|
1 | 100 | FIRM |
2 | 200 | CANCELLED |
3 | 300 | DELETED |
DeleteOrderStatus:
OrderStatus |
---|
CANCELLED |
DELETED |
Desired Output in Fact Table:
Order# | Amount | OrderStatus |
---|---|---|
1 | 100 | FIRM |
After loading the Fact table, I would like to delete records that have certain OrderStatus that are in 'DeleteOrderStatus' table. Using KEEP/INNER JOIN, I was able to include certain records. Is there a way I can exclude certain records based on another table?
Thanks in advance.
You can use the Exists() function in a WHERE clause:
Filter:
LOAD OrderStatus as Status2Exclude
FROM DeleteOrderStatus;
Facts:
LOAD * FROM FactTable
WHERE NOT EXISTS(Status2Exclude, OrderStatus);
Exists() is the way to go!
Additionally, if you want to keep your load optimized (if qvd is your source), dont't rename OrderStatus field and use:
where not Exists(OrderStatus). It is faster.
As Stefan mentioned where not exists() would be the ideal one to handle this . Please let us know if that didn't work
It worked. Thank you Stefan and Raviteja.
Is there any reason why the field name in the filter was changed? The reason I am asking is when I tried to use the same field name twice as below, the filter did not work properly. Could you please explain why the below ocde does not work?
Filter:
LOAD OrderStatus
FROM DeleteOrderStatus;
Facts:
LOAD * FROM FactTable
WHERE NOT EXISTS(OrderStatus, OrderStatus);
Hi Vamshi , NOT EXISTS(OrderStatus, OrderStatus); Compares values of Field(1st in arguments) from Current table from the already available field (2nd in the arguments)in the memory..
you could try just where not exists(OrderStatus) if incase you want to use only same field.
Please mark Helpful or Answered so that it helps for the community.
Thanks
CY
Thank you Raviteja for the clarification.
Please mark as Answered to close the thread.. Have a great day.
Thanks
When using
...
WHERE NOT EXISTS(OrderStatus);
instead of the two argument version, you won't get all requested records if OrderStatus is not a primary key (which I assume it is not).
In other words, as soon as your LOAD encountered the first record with OrderStatus FIRM, FIRM is part of the symbols that the exists() function checks the upcoming record values against. Hence, no other records with OrderStatus FIRM will pass the WHERE clause and will be loaded to the resident output table.
I guess that's what you see when you are mentioning that this approach 'will not work properly', right?
Thank you Stefan and Chaitanya!