Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 sql syntax help

Author  Topic 

REEPER
Yak Posting Veteran

53 Posts

Posted - 2007-02-08 : 16:50:04
Hello,
I have 2 tables in 1 table(KEKO) I have 2 fields of intrest: MaterialID and VaildDate in which I need to capture the MaterialID with the MAX ValidDate:

SELECT MaterialID, MAX(VaildDate) AS CurrrentPricePeriod
FROM KEKO
GROUP BY MaterialID

That all works great. But I need to join those results to another table(CKIS) where they would be joined by the MAX(ValidDate) and MaterialID.

MCP, MCSD

X002548
Not Just a Number

15586 Posts

Posted - 2007-02-08 : 16:54:59
SELECT * FROM CKIS C
JOIN (
SELECT MaterialID, MAX(VaildDate) AS CurrrentPricePeriod
FROM KEKO
GROUP BY MaterialID) AS XXX
ON XXX.Current_PricePeriod = c.dtKey
AND xxx.material_id = c.Material_id


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

REEPER
Yak Posting Veteran

53 Posts

Posted - 2007-02-09 : 13:50:17
That did it.

THX!

MCP, MCSD
Go to Top of Page
   

- Advertisement -