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

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!
Norm-alNetwork EngineerAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
mmr159Connect With a Mentor Commented:
SELECT MAX(CalendarDays)
FROM (
    SELECT     TOP (5) CalendarDays
    FROM         Calendar
    WHERE     (CalendarDays >= '11/15/11') AND (OfficeWorkdays <> 'Workday')
    ) AS t
0
 
PresageSolutionsCEOCommented:
Can you please give some more detail? I can not understand your requirement.
0
 
mmr159Commented:
OR... you might want to use MIN... depending on what you mean by "Last" record.
0
 
Norm-alNetwork EngineerAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.