Re: SP Question
From: Jesse Bilsten (jesse_at_vreo.com)
Date: 03/02/04
- Next message: Bart Simpson: "Re: How to create maintenance plan without Northwind and Pubs"
- Previous message: Dave: "semmap.dll"
- In reply to: Uri Dimant: "Re: SP Question"
- Next in thread: Sonya: "Re: SP Question"
- Reply: Sonya: "Re: SP Question"
- Messages sorted by: [ date ] [ thread ]
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.
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
- Next message: Bart Simpson: "Re: How to create maintenance plan without Northwind and Pubs"
- Previous message: Dave: "semmap.dll"
- In reply to: Uri Dimant: "Re: SP Question"
- Next in thread: Sonya: "Re: SP Question"
- Reply: Sonya: "Re: SP Question"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|