Solved

How to retrieve the LAST record from a TOP(5) SQL Select Statement

Posted on 2011-09-27
4
444 Views
Last Modified: 2012-05-12
SELECT     TOP (5) CalendarDays
FROM         Calendar
WHERE     (CalendarDays >= '11/15/11') AND (OfficeWorkdays <> 'Workday')

Returns 5 records of calendar days. How can I retrieve the last record/date from within Delphi? I need to assign a variable to that last record...

Thanks!
0
Comment
Question by:Bianca
  • 2
4 Comments
 

Expert Comment

by:PresageSolutions
ID: 36712035
Can you please give some more detail? I can not understand your requirement.
0
 
LVL 7

Accepted Solution

by:
mmr159 earned 500 total points
ID: 36712039
SELECT MAX(CalendarDays)
FROM (
    SELECT     TOP (5) CalendarDays
    FROM         Calendar
    WHERE     (CalendarDays >= '11/15/11') AND (OfficeWorkdays <> 'Workday')
    ) AS t
0
 
LVL 7

Expert Comment

by:mmr159
ID: 36712046
OR... you might want to use MIN... depending on what you mean by "Last" record.
0
 

Author Comment

by:Bianca
ID: 36712050
SELECT     MAX(CalendarDays) AS CalendarDays
FROM         (SELECT     TOP (5) CalendarDays
                       FROM          Calendar
                       WHERE      (CalendarDays >= '11/15/11') AND (OfficeWorkdays = 'Workday')) AS Calendar_1

I got it a minute before seeing this post, thanks for your help!!!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question