title: SQL to down date values from another table
body: <p>I am not sure this is even feasible in SQL, but if anyone has any ideas let me know. I have a a bunch of values for stock due in, but the same item could have multiple dates due in. I then have a list of dates stock is due out in and amount in a different table. I want to look up how much stock can go out on each sales line.</p>
  
  <p>The tricky portion for me is that it could source from two incoming lines. If there was only ever 1 incoming line, it would be easy. Just use a sub query on each line. However the fact that each sales line could pull from multiple lines in another table makes it much more complicated. Does anyone have any ideas on how best to do this in SQL. Would be easy for me outside of this, but there is a lot of data so for performance want to keep it in SQL.</p>
  
  <p>Example data below:</p>
  
  <p><img src="https://i.stack.imgur.com/fAR2Z.png" alt="Image"></p>