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
 General SQL Server Forums
 New to SQL Server Programming
 max value

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2008-08-13 : 14:55:13

I have an order detail table. I want to grab the unit price field out of the table which has the highest requested date.

So if a record has a request date of today I want the unit price from that record.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-08-13 : 14:56:11
you'll have to show us your table structure for this.

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.0 out!
Go to Top of Page

Vack
Aged Yak Warrior

530 Posts

Posted - 2008-08-13 : 14:58:06
Not sure exactly what you need.

Table: OELINHST
FIELDS:
ORD_NO
ITEM_NO
CUS_NO
REQUESTED_DT
UNIT_PRICE
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-08-13 : 15:01:23
table structure, sample data and expected result based on that sample data.

select * from OELINHST
where REQUESTED_DT = (select max(REQUESTED_DT) from OELINHST where REQUESTED_DT < getdate())


_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.0 out!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-14 : 01:17:43
or this (not sure what you exactly want)

SELECT m.*
FROM OELINHST m
INNER JOIN (SELECT ORD_NO,MAX(REQUESTED_DT) AS MaxDate
FROM OELINHST
GROUP BY ORD_NO)t
ON t.MaxDate=m.REQUESTED_DT
AND t.ORD_NO=m.ORD_NO
Go to Top of Page
   

- Advertisement -