Solved

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

Posted on 2011-09-27
4
442 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now