-
Request the last "n" rows
I know how to use the Top function but how can I retieve the last "n" records
from a table using "n" as a variable. I tried using a negative number but
that didn`t work.
Any advice or link is appreciated.
PhilipL
-
Re: Request the last "n" rows
"PhilipL" <aplatfl@aol.com> wrote:
>
>I know how to use the Top function but how can I retieve the last "n" records
>from a table using "n" as a variable. I tried using a negative number but
>that didn`t work.
>
>Any advice or link is appreciated.
>
>PhilipL
I am using sql server 7 with vb.
-
Re: Request the last "n" rows
order by the field you want to pick by (descending order) and still use top
N in your select statement...
Chris
"PhilipL" <aplatfl@aol.com> wrote:
>
>"PhilipL" <aplatfl@aol.com> wrote:
>>
>>I know how to use the Top function but how can I retieve the last "n" records
>>from a table using "n" as a variable. I tried using a negative number but
>>that didn`t work.
>>
>>Any advice or link is appreciated.
>>
>>PhilipL
>
>I am using sql server 7 with vb.
-
Re: Request the last "n" rows
Use
DECLARE @i INTEGER
SET @i = 10
SET ROWCOUNT @i
SELECT * FROM tbl ORDER BY DateField DESC
or
SELECT * FROM tbl
WHERE PK IN(SELECT * FROM tbl ORDER BY dateField DESC)
ORDER BY DateField ASC
SET ROWCOUNT 0
Play with this I think this is what you need.
Scott
"PhilipL" <aplatfl@aol.com> wrote:
>
>I know how to use the Top function but how can I retieve the last "n" records
>from a table using "n" as a variable. I tried using a negative number but
>that didn`t work.
>
>Any advice or link is appreciated.
>
>PhilipL
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks