Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Lookup to find

$
0
0

Hello,  I have two CTE and the first returns records like:

Item, date used

123 , 03/01/2013

123, 05/13/2013

The second CTE returns:

item, Date stocked

123,  01/01/13

123, 02/15/13

123, 04/16/13

123, 05/12/13

123, 07/01/13

How would I get the first CTE to show the 'Date stocked'? The date stock should be the maximum date in CTE2 prior to the date used. for instance, the results would look like:

item, date used, date stocked

123, 03/01/2013, 02/15/13

123, 05/13/2013,  05/12/13

THANKS IN ADVANCE!



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>