I have table1 with fields KEY1, KEY2, QNTY
rows :
1234, 1, 1000
1234,2,2000
1235,1,4000
1235,2,5000
1235,5,6000
KEY1+KEY2 will be unique in this table
I have table2 with fields KEY1, KEY2, SDATE, SQNTY
Rows:
1234,1,A,500
1234,1,B,500
1234,1,C,500
1234,2,A,1000
1234,2,Q,1000
1234,2,Z,1000
1235,1,A,2500
1235,1,B,2500
1235,1,G,2500
1235,2,S,5000
1235,5,D,4000
1235,5,D,4000
The totals of SQNTY for KEY1+KEY2 in Table2 are shown as more than the corresponding QNTY of KEY1+KEY2 in Table1
I want to skip through Table1, and pick out rows from Table2 matched over KEY1+KEY2 which is ordered by KEY1+KEY2+SDATE(desc) till the sum of SQNTY is greater or equal to QNTY in Table1. If the sum is greater, the SQNTY for the last row
is re ...
Go to the complete details ...