Saturday, February 25, 2012

Retrieve only last 4 records. Date descendent ordered.

Hello,
I want to load only the last 4 records of a MSSQL table considering they
are ordered descendent by date. What should my SQL be?
Thank You,
MiguelHi
You can use the TOP function to do this. See Books online for more details
SELECT TOP 4 MyDate
FROM MyTable
ORDER BY MyDate DESC
John
"Shapper" <mdmoura*NOSPAM*@.gmail.*DELETE2SEND*com> wrote in message
news:eGCRmjmTFHA.2172@.tk2msftngp13.phx.gbl...
> Hello,
> I want to load only the last 4 records of a MSSQL table considering they
> are ordered descendent by date. What should my SQL be?
> Thank You,
> Miguel
>|||DECLARE @.intMyCount int
SET @.intMyCount = 4
SET ROWCOUNT @.intMyCount
SELECT MyDate
FROM MyTable
ORDER BY MyDate DESC
-- disable rowcount
SET ROWCOUNT 0
Message posted via http://www.webservertalk.com

No comments:

Post a Comment