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

advanced join

$
0
0

Hi All,

I am trying to figure out how to do this and appreciate any help. Basically, I have two tables shown below. I need to join the orders table with the shipments table on Customer IDand on date so that for each date from the Orders table, I need to grab the first date that comes right after it from the shipments table. Thank in advance!!

DECLARE @Orders TABLE (CustomerID VARCHAR(100), Ship_Date DATE)

INSERT INTO @Orders
SELECT 123, '01/01/2013'
UNION ALL
SELECT 123, '01/19/2013'
UNION ALL
SELECT 123, '03/01/2013'

DECLARE @Shipments TABLE (CustomerID VARCHAR(100), Recived_Date DATE, ShipTo VARCHAR(100))

INSERT INTO @Shipments
SELECT 123, '01/15/2013', 'ABC'
UNION ALL
SELECT 123, '02/02/2013', 'XYZ'
UNION ALL
SELECT 123, '05/01/2013', 'SAD'



Viewing all articles
Browse latest Browse all 23857

Trending Articles



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