Alright, people,
I have a table with stock of products in a network with 13 stores. I want to block items that have no inventory in any store and that have not had sales in the last year or that were only registered, but did not sell. I tried the script below:
UPDATE PRXLJ
SET Flg_BlqCom = 1, Flg_BlqVen = 1
WHERE Qtd_Saldo= 0
AND (YEAR(Dat_UltVen) <2017
OR Dat_UltVen IS NULL)
where:
- Flg_BlqCom = 1 blocked for purchase
- Flg_BlqVen = 1 blocked for sale
- Flg_BlqCom = 0 unlocked for purchase
- Flg_BlqVen = 0 unlocked for sale
The problem is that even on the central server the stores are distributed in the store-to-store table and do not want to block if you have at least one drive in any branch. the same product code is repeated 13 times, one for each store. When I ran this script, it blocked the products according to the stock and last sale of each store, blocking one product in some stores and not in other stores.
The table structure looks like this:
I need a script that blocks only the product that has no stock in any store and that has not been sold after 01/01/2017 in any store as well.
Using Sql Server 2008 This table has about 60 thousand items (considering that there are 13 stores, they are around 780 thousand lines) and I want to leave unlocked about 15 thousand items or less that are in fact active. For tax purposes I can not delete the old items, just block them. I do not know if the information was enough for understanding, but if you need more data let me know.