Board index » delphi » TADOQuery get last record from result set

TADOQuery get last record from result set

Hi NS,

How about:

Quote
> select ServerDate from LOGTABLE
> where Machine = 'PRINT1'
> order by ServerDate DESC

and selecting the first record?

If you don't want to change your Select, maybe you can apply a Filter with
DESC before retrieving the first record and then clear it afterwards (I
don't know if it will be faster than doing Last though).

Thrse

 

Re:TADOQuery get last record from result set


I am using a TADOQuery with a client side cursor (it must be) and trying to
perform a query to retrieve only the last record of the retrieved result
set.

Using the Query Analyzer with SQL 7 I can perform the following query and
retrieve the last record of the resulting data:

DECLARE Log_Cursor CURSOR KEYSET FOR
select ServerDate from LOGTABLE
where Machine = 'PRINT1'
order by ServerDate asc
OPEN Log_Cursor
FETCH LAST FROM Log_Cursor
CLOSE Log_Cursor
DEALLOCATE Log_Cursor

However trying to get this to work in Delphi5 is a problem.

Using:
select ServerDate from LOGTABLE
where Machine = 'PRINT1'
order by ServerDate asc

and then doing a ADOQuery1.Last to get my record is much slower than the
method at the top of this post.

Does anyone know how I can retrieve just the last record of a retrieved
result set using a TADOQuery?

Thanks for any help in advance.

Re:TADOQuery get last record from result set


Many thanks for the suggestion - I had already tried this and there is not
any difference.

The problem I am trying to overcome using my client side ADOQuery (I can't
use server side) is that instead of pulling down 2000 to 10000 records and
then navigating first or last, I only want to pull down the last record of
the result set in the same way my SQL 7 query does that I showed in my first
post.

I have searched Mers etc. and so far I have not been able to crack this yet.

Quote
"Thrse Hanquet" <therese.hanq...@skynet.be> wrote in message

news:3b1f664a$1_1@dnews...
Quote
> Hi NS,

> How about:

> > select ServerDate from LOGTABLE
> > where Machine = 'PRINT1'
> > order by ServerDate DESC

> and selecting the first record?

Re:TADOQuery get last record from result set


How about this

Quote
> select ServerDate from LOGTABLE
> where Machine = 'PRINT1'
> order by ServerDate asc

select top 1 ServerDate from LOGTABLE
where Machine = 'PRINT1'
order by ServerDate desc

J. Johansen

Re:TADOQuery get last record from result set


Perfect!!

Many thanks for your help.

Quote
"J?rn Johansen" <jornj...@nospam.online.no> wrote in message

news:3b1f8f4d$1_1@dnews...
Quote
> How about this

> > select ServerDate from LOGTABLE
> > where Machine = 'PRINT1'
> > order by ServerDate asc

> select top 1 ServerDate from LOGTABLE
> where Machine = 'PRINT1'
> order by ServerDate desc

> J. Johansen

Other Threads