I am trying to find a way to match two sets of numbers by adding one set of number together to get the other set.
For example:
In the above example, the numbers in #Stage are also in #Ship. I have them in order here but they don't have to be. 12 + 20 = 32, 10 + 20 + 16 = 46 etc.
I want to be able to come up with the ShipID's that when added together go with each #Stage row.
Not sure if this is possible but thought I would ask.
Thanks,
Tom
For example:
Code:
If OBJECT_ID('tempdb..#Stage') IS NOT NULL
DROP TABLE #Stage
If OBJECT_ID('tempdb..#Ship') IS NOT NULL
DROP TABLE #Ship
CREATE TABLE #Stage
(
StageID int,
ShipNumber varchar(10),
PONumber varchar(10),
iQty int
)
CREATE TABLE #Ship
(
ShipID int,
ShipmentNumber varchar(10),
Units int
)
INSERT #Stage (StageID, ShipNumber, PONumber, iQty) VALUES (20, 'MZ12345', 'A4735', 32)
INSERT #Stage (StageID, ShipNumber, PONumber, iQty) VALUES (22, 'MZ12345', 'A4735', 46)
INSERT #Stage (StageID, ShipNumber, PONumber, iQty) VALUES (23, 'MZ12345', 'A4735', 60)
INSERT #Stage (StageID, ShipNumber, PONumber, iQty) VALUES (35, 'MZ12345', 'A4735', 18)
INSERT #Stage (StageID, ShipNumber, PONumber, iQty) VALUES (36, 'MZ12345', 'A4735', 26)
Insert #Ship (ShipID, ShipmentNumber, Units) VALUES (250, 'MZ12345', 12)
Insert #Ship (ShipID, ShipmentNumber, Units) VALUES (251, 'MZ12345', 20)
Insert #Ship (ShipID, ShipmentNumber, Units) VALUES (252, 'MZ12345', 10)
Insert #Ship (ShipID, ShipmentNumber, Units) VALUES (253, 'MZ12345', 20)
Insert #Ship (ShipID, ShipmentNumber, Units) VALUES (255, 'MZ12345', 16)
Insert #Ship (ShipID, ShipmentNumber, Units) VALUES (300, 'MZ12345', 30)
Insert #Ship (ShipID, ShipmentNumber, Units) VALUES (310, 'MZ12345', 30)
Insert #Ship (ShipID, ShipmentNumber, Units) VALUES (320, 'MZ12345', 6)
Insert #Ship (ShipID, ShipmentNumber, Units) VALUES (330, 'MZ12345', 12)
Insert #Ship (ShipID, ShipmentNumber, Units) VALUES (340, 'MZ12345', 16)
Insert #Ship (ShipID, ShipmentNumber, Units) VALUES (350, 'MZ12345', 5)
Insert #Ship (ShipID, ShipmentNumber, Units) VALUES (360, 'MZ12345', 5)
In the above example, the numbers in #Stage are also in #Ship. I have them in order here but they don't have to be. 12 + 20 = 32, 10 + 20 + 16 = 46 etc.
I want to be able to come up with the ShipID's that when added together go with each #Stage row.
Not sure if this is possible but thought I would ask.
Thanks,
Tom