SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


iterate through a list and add to group


iterate through a list and add to group

Author
Message
Talvin Singh
Talvin Singh
SSC Eights!
SSC Eights! (914 reputation)SSC Eights! (914 reputation)SSC Eights! (914 reputation)SSC Eights! (914 reputation)SSC Eights! (914 reputation)SSC Eights! (914 reputation)SSC Eights! (914 reputation)SSC Eights! (914 reputation)

Group: General Forum Members
Points: 914 Visits: 254
hi all,
i have a university assignment around an order allocation system for a spare parts business. I need to allocate orders to one of 4 shelf position, which have been assigned a check point. so orders for that check point get placed into shelf, but once there are more than or equal to 5 items in that shelf position, it gets assigned an id. the next set of orders come through and will check of space for those shelves that are not full once all shelf have exceeded 5 items, all those orders are part of that id, lets say IS= 1.


as you can see there is a shelf location table on the right. it gets allocated a checkPoint. the group of orders come through along with items and checkPoints. the green area is the iteration i require to go through each line and update the Shelf, Items In CheckPoint and Group columns.
order1 happens to be for checkPoint 20, therefore shelf A. current items in order is 2, as its >= 5 items in shelf A, its assigned to Group 1.
order2 is for shelf A, current items in shelf A is now 3, still not over 5, therefore Group 1. and so on.
order6 is for shelf A, current items in shelf A is now 6, as its >= 5 it gets assigned group 1 but it can no longer take on an orders in shelf A.
order7 is for Shelf A, as it is full, it marks is as group 0.
and so on. same thing happens with shelf position B.

the next wave of orders will come through, and will try to fill any open remaining shelf positions with orders. this wave could include the orders missed in previous wave, as i will be selecting all orders where Group = 0.

once all shelves have been filled (by exceeding 5 items and marking as full) , or no more remaining orders are for that checkPoint, then 4 new checkPoints will be allocated to the 4 shelf positions and they will get assigned Group ID = 2.

Hopefully i make sense. This is similar to another post i created here (its for the same assignment) but i think this logic will work.

Below is code for temp tables above. By all means suggest a new way, i may not need some columns...

Many thanks


SELECT *
INTO #ShelfPosition
FROM (VALUES
('A', 0,0,0),
('B', 0,0,0),
('C', 0,0,0),
('D', 0,0,0)
)v(Shelf, CheckPoint, Items, isFull);



SELECT *
INTO #Orders
FROM (VALUES
(1, 2, 20),
(2, 1, 20),
(3, 4, 84),
(4, 2, 12),
(5, 1, 65),
(6, 3, 20),
(7, 1, 20),
(8, 2, 84),
(9, 2, 10),
(10, 2, 5)
)v(orderID, Items, CheckPoint);

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search