>Don't know what I would do without UT's help.
>
>I have a table with part number, status, datestamp fields. There can be several records of each part number.
>
>I need to know how many records have a ststus of 2 by part number with highest date stamp. I see the need to group by part number in date stamp order, take the latest date and see if the status is 2 and get a total count of these.
Try
select count(distinct PartNo) from Parts P where Status = 2 and PkField = (select top 1 PKField from
Parts P1 where P1.PartNo = P.PartNo order by DateStamp DESC)
If it's not broken, fix it until it is.
My Blog