Quantcast
Channel: Toad Data Point Forum - Recent Threads
Viewing all articles
Browse latest Browse all 2544

Possible loop needed

$
0
0

Hi all! I am new to the forum and new to Toad Data Point. I have written a query that I am having trouble finishing. My query identifies overstocked item/locations and understocked item/locations and matches them up together in order to send merchandise from one location to another. The issue I am having is figuring out some type of loop process to determine which stores to send the items to. I need my query to first look at stores within the same district, then move onto stores within the same state, then move onto stores within the same region. For the stores in the same region I want it to order by who can take the most units. All while adding the quantity of the receiving stores as it goes until it fulfills all of the quantity from the sending store.

Example: Item 123 at Store A has 156 units it needs to transfer out. Store A is in district 307, in Virginia, in region 8796. Below are the results for the stores than need item 123.

I need the query to result that store 'I' can take the merchandise first at 24 units (same district). Then 'G' at 12 units, then 'H' at 12 units, then 'J' at 6 units (same state). Then 'K' at 40 units, then 'B' at 35 units, lastly at 'C' for 27 units (to sum to the total of 156 units).

STOREDISTRICTSTATEREGIONQTY
B206MD879635
C1338NY879630
D206MD879618
E927FL87966
F1675ME87966
G330VA879612
H311VA879612
I307VA879624
J311VA87966
K206MD879640

I have been wracking my brain and looking at examples and cannot figure out where to start? Multiple case statements? Separate queries that create an order?

Any help will be greatly appreciated.


Viewing all articles
Browse latest Browse all 2544

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>