October 26, 2007 at 2:30 pm
Another Brain fart.
Table_A Code, Price
Table_B Code , Eff_date, Price
Update Table_A Set Price = Table_B.Price where MAX(Table_B.Eff_Date)
If Table_A Code & Price
CODE1, 20.00
COde2, 30.00
And Table_B Code, Eff_Date & Price
CODE1, 1/1/2004, 20.00
CODE1, 2/5/2007, 30.00
CODE2, 1/1/2004, 20.00
CODE2, 3/1/2006, 40.00
CODE2, 7/1/2007, 25.00
Then After Update TABLE_1 Code, Price
CODE1, 30.00
CODE2, 25.00
I know, beginner, but it IS Friday.
October 26, 2007 at 2:57 pm
October 26, 2007 at 2:59 pm
UPDATE
A
SET
Price =B.Price
FROM
Table_A A
INNER JOIN
Table_B B
INNER JOIN
(SELECT Code, Max(EFF_DATE) Max_Eff_Date FROM Table_B GROUP BY Code) C
ON
B.Code = C.Code AND
B.EFF_DATE = C.Max_Eff_Date
ON
A.Code = B.Code
October 26, 2007 at 3:12 pm
This is bringing back dup's. The right price, but assigned for number of dates found in table B.
October 26, 2007 at 3:29 pm
October 26, 2007 at 4:16 pm
The only way you should get dupes with mine is you have multiple dates the same per code. If that is the case then how do you propose to resolve selection?
October 29, 2007 at 5:38 am
My Mistake.
The duplicate's orgininate in Table_A, which is ok. The fact they are getting adsigned max(price) looks right.
Thanks.
Randy.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply