Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assign QTY Based on Priorities

Status
Not open for further replies.

CptTom

Programmer
Jul 16, 2001
117
US
I need to assign quantities from Table_A based on Priorities in table_B when Table_B has multiple Priorities. Table_B has a required quantity based on priority and may have more than 1 priority but not more than 3 priorities.

Here is how I am trying to work it.

DECLARE @Cat_Count INT, @Unassigned_Qty INT


Select Disinct OperationCenter, make, count(Priorities) AS Cat_Count
Into temp_table FROM table_B GROUP BY OperationsCenter, make
ORDER BY OperationsCenter, make

SET @CAT_COUNT = temp_table.Cat_Count
SET @Unassigned_Qty = Table_A.OnHand

Update table_B
SET OH_QTY = and here is where I get stuck.

I need to run a While @CAT_COUNT > 1 AND @Unassigned_Qty > 0

(IF) WHEN Priority = 1 Then set On_Hand = Required - @Unassigned_Qty
SET @Unassigned_Qty = @Unassigned_Qty – What was assigned on line above
THEN
IF(WHEN) Priority = 2 Then On_Hand = Required - @Unassigned_Qty
SET @Unassigned_Qty = @Unassigned_Qty – What was assigned on line above
THEN
IF(WHEN) Priority = 3 Then On_Hand = Required - @Unassigned_Qty
SET @Unassigned_Qty = @Unassigned_Qty – What was assigned on line above
THEN
IF(WHEN) Priority = 4 Then On_Hand = Required - @Unassigned_Qty
SET @Unassigned_Qty = @Unassigned_Qty – What was assigned on line above

Always in that order, Priority 1 - 4
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top