Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Syntax help
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01398006
Message ID:
01398008
Views:
59
>Hi All,
>
>Brain freeze....having the following table how do I get the EDP and Alert Flg for the max(CaptureDate) ?
>
>
>CaptureDate			EDP	AlertFlg
>2009-01-05 15:28:21.860		15382	Zero
>2009-02-05 15:29:32.860		15382	Scheduled
>2009-03-05 15:29:31.860		15382	Low
>2009-01-05 15:28:21.860		32522	BO
>2009-02-05 15:29:32.860		32522	Zero
>2009-03-05 15:29:31.860		32522	Zero
>
>
>EDP	AlertFlg
>15382	Low
>32522	Zero
>
>
>Thank you,
>Daniel

SQL Server 2005 and up
select * from (select *, row_Number() over (Order by CaptureDate DESC) as RowNumber from myTable) D where RowNumber = 1
BTW, if you have multiple records with the same date, then this solution would not work, you can use RANK() instead.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform