Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Syntax help
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01398006
Message ID:
01398008
Vues:
60
>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform