Re: SP Question

From: Jesse Bilsten (jesse_at_vreo.com)
Date: 03/02/04


Date: Tue, 2 Mar 2004 10:38:25 -0800

You could just use a MAX function to attain the last record if you know the
criteria. If the last record will be based on a date field, use Max on the
date field or if it's an identity, likewise. There are many different
applications of this same idea to reach the end of your recordset with much
less overhead than a cursor. It all depends on how well you know your data.

"Uri Dimant" <urid@iscar.co.il> wrote in message
news:OA81p2EAEHA.688@tk2msftngp13.phx.gbl...
> Hi, Hari
> Shame on you , do you suggest him to use a cursor to get the last row? :)
>
>
> "Hari" <hari_prasad_k@hotmail.com> wrote in message
> news:e7qrKYBAEHA.2432@TK2MSFTNGP11.phx.gbl...
> > Hi,
> >
> > In RDBMS there is no real concept of the first or last row in a result
set
> > or table. I feel that this requirement might not come for any business
> > logics.
> > Still go thru the below to get information on how to acheve it.
> >
> > First record you can retrive using TOP clause in select statement.
> >
> > Eg: Select top 1 * from tablename
> >
> >
> > But the last record, You need to use cursor with FETCH LAST. This will
> takes
> > lots of overhead.
> >
> > Eg: from Books online
> >
> > DECLARE authors_cursor SCROLL CURSOR FOR
> > SELECT au_lname, au_fname FROM authors
> > ORDER BY au_lname, au_fname
> >
> > OPEN authors_cursor
> >
> > -- Fetch the last row in the cursor.
> > FETCH LAST FROM authors_cursor
> > CLOSE authors_cursor
> > DEALLOCATE authors_cursor
> > GO
> >
> > Thanks
> > Hari
> > MCDBA
> >
> >
> >
> >
> > "Ray Higdon" <sqlhigdon@nospam.yahoo.com> wrote in message
> > news:e3SY3B$$DHA.1548@TK2MSFTNGP12.phx.gbl...
> > > What type of table and column?
> > >
> > > Lookup MAX, MIN, TOP in BOL
> > >
> > > --
> > > Ray Higdon MCSE, MCDBA, CCNA
> > > ---
> > > "Sonya" <sjerb@hotmail.com> wrote in message
> > > news:OEpMQp%23$DHA.2216@TK2MSFTNGP10.phx.gbl...
> > > > Is there any way to grab the first and last record of a table using
a
> > > stored
> > > > procedure? I am new to stored procedures and apologize if this is a
> > silly
> > > > question. Thanx in advance.
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Relevant Pages

  • Re: select mline returns truncated values
    ... > SELECT MLINEFROM zoot WHERE SelectMe ... Look at the structure of your cursor. ... This is what VFP does - it evaluates the first record in the ... > the first record is not included in the output set, ...
    (microsoft.public.fox.programmer.exchange)
  • select mline returns truncated values
    ... CREATE CURSOR zoot ... SELECT MLINEFROM zoot WHERE SelectMe ... The filter on SelectMe proves this, as the first record is not included ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Search and Replace gives GPF error
    ... I can only get it to work if the cursor is on the first record of parent ... Both as TableFrames with 5-9 rows showing. ... operation Customer is only showing one row. ...
    (comp.databases.paradox)
  • Re: wm5 contact list default with name
    ... you can still accomplish this by highlighting the contact name and using the left/right cursor to select the default number/method to contact the contact. ... Noticed also that after you "find" a contact using the filter, where the app used to leave that record as the entry point, as soon as you clear the filter, it goes back to the first record in the database... ...
    (microsoft.public.pocketpc)
  • Re: Embedded SQL, sub-procedures and activation groups
    ... the cursor being closed when the program ends. ... My exposure to ILE suggests that this causes more overhead to be incurred when the program is called, but the program isn't called frequently anyway, and probably only by a few users. ...
    (comp.sys.ibm.as400.misc)