I'm trying to update Table1 in DB1 with data from Table2 in DB2. I can connect and get the data from DB2 Table2 into DB1 Table1, but the issue I'm having is getting the MOST RECENT data from DB2 Table2.
I'm looking at 3 fields in DB2: f1, f2, & f3. f1 contains duplicates (and is where I'm matching from DB1 Table1) and f3 is a date field and I want to grab the most recent date to update DB1 Table1. Below is some of the code I've been using:
Update Table1
Set f2 = c.f2,
f3 = convert(varchar, c.f3, 101)
From Table1 b
inner join Server.DB.dbo.Table2 c on b.f1 = c.f1
Where b.f1 = c.f1
Sample Data:
c.f1 c.f2 c.f3
8456 RS47354 06/30/2009
8456 M101021 10/31/2009 (want this one)
7840 5574 NULL
7840 RH013057 06/30/2010 (want this one)
7650 RS48100 06/30/2007
7650 RS49010 06/30/2009 (want this one)
b.f1 b.f2 b.f3
8456 Null Null
7840 Null Null
7650 Null Null
Eventually, this will be set inside an SSIS package.
Any and all help appreciated!
-JFV