• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 458
  • Last Modified:

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!
0
Norm-al
Asked:
Norm-al
  • 2
1 Solution
 
PresageSolutionsCommented:
Can you please give some more detail? I can not understand your requirement.
0
 
mmr159Commented:
SELECT MAX(CalendarDays)
FROM (
    SELECT     TOP (5) CalendarDays
    FROM         Calendar
    WHERE     (CalendarDays >= '11/15/11') AND (OfficeWorkdays <> 'Workday')
    ) AS t
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now