JaedenRuiner
Well-known member
- Joined
- Aug 13, 2007
- Messages
- 340
- Programming Experience
- 10+
Alrighty,
You all have been awesome, and have gotten me this far, and though I have many ways to do this next part (one of which i'll be coding now) but I was thinking to ask in case there was a better way to do it.
I have four tables:
Customer
BOL (bill of lading)
Email
Material
Customer is PK to BOL FK and Email FK
Each BOL has up to 4 unique Materials, and their quantities.
The IDEA:
After inserting all the BOLs from the XLS file into the BOL Table, I need to break them down OVER Customer ID's, but split the individual BOL ids into the EMail table via a Partial Sum of BOL Materials.
You confused yet. Okay, here's the example:
Customer
My target is 350, so for Customer 100, they have 4 BOLs where Material ID 1 breaks 350 at the 3rd entry. So I'm looking so have marker that when the Sum of MatID 1's Qty > 350, mark all those BOLs as children of an entry in the Email table, and then Create a new Email for that customer for the next set of BOLs.
I can do this programmitically, retaining the sum for myself, as well, the insertion into the Email table is handled with a stored procedure, since the Email_ID PK is a formatted field based on the Customer ID and an Incrementing Number per customer, but I was curious if there was a way this could be done with SQL and the Server doing some of the work for me. *chuckle*
thanks
You all have been awesome, and have gotten me this far, and though I have many ways to do this next part (one of which i'll be coding now) but I was thinking to ask in case there was a better way to do it.
I have four tables:
Customer
BOL (bill of lading)
Material
Customer is PK to BOL FK and Email FK
Each BOL has up to 4 unique Materials, and their quantities.
The IDEA:
After inserting all the BOLs from the XLS file into the BOL Table, I need to break them down OVER Customer ID's, but split the individual BOL ids into the EMail table via a Partial Sum of BOL Materials.
You confused yet. Okay, here's the example:
Customer
- ID=100
BOL- ID=27364
- MatID=1
- Qty=125
- MatID=2
- Qty=1000
- ID=27365
- MatID=1
- Qty=200
- MatID=2
- Qty=650
- ID=27366
- MatID=1
- Qty=40
- MatID=2
- Qty=22
- ID=27367
- MatID=1
- Qty=75
- ID=27364
My target is 350, so for Customer 100, they have 4 BOLs where Material ID 1 breaks 350 at the 3rd entry. So I'm looking so have marker that when the Sum of MatID 1's Qty > 350, mark all those BOLs as children of an entry in the Email table, and then Create a new Email for that customer for the next set of BOLs.
I can do this programmitically, retaining the sum for myself, as well, the insertion into the Email table is handled with a stored procedure, since the Email_ID PK is a formatted field based on the Customer ID and an Incrementing Number per customer, but I was curious if there was a way this could be done with SQL and the Server doing some of the work for me. *chuckle*
thanks