SELECT *,ROW_NUMBER() OVER (PARTITION BY idtestata ORDER BY ISNULL(Versione,0) DESC) AS MaxVersioneFROM table TWHERE datacreazione BETWEEN GETDATE()-1 and GETDATE() or CONVERT(DATE,datacreazione) = CONVERT(DATE,GETDATE() )ORDER BY idtestata,datacreazione desc
Leggi tutto il post...