Get the last record in a dataset

G

Guest

I am trying to move to the last record in a dataset and find out the next incremented number that will be created via an insert. I a have tried a count but this does not quite do as I need. As the number of records does not relate to the next incremented number. Could anybody help me with this please??

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
I

Ignacio Machin \( .NET/ C# MVP \)

hi,

select top 1 fieldname from table order by fieldname desc

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

wrote in message news:[email protected]...
I am trying to move to the last record in a dataset and find out the next
incremented number that will be created via an insert. I a have tried a
count but this does not quite do as I need. As the number of records does
not relate to the next incremented number. Could anybody help me with this
please??
**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP &
ASP.NET resources...
 
A

Andy Becker

ote in message news:[email protected]...
I am trying to move to the last record in a dataset and find out the next
incremented number that will be created via an insert. I a have tried a
count but this does not quite do as I need. As the number of records does
not relate to the next incremented number. Could anybody help me with this
please??

Ignacio's bit of SQL can help you in a single-user environment, assuming you
are not using any identity columns in the database. With multi-user or
identities, things get messier...

Mind if I ask what you want to do with the value? There might be a
different way to do what you're after.

Best Regards,

Andy
 
G

Guest

This can also help you:
select max(fieldname) from tablename

you can obtain the new value by using:

select max(fieldname)+1 from tablename

Note: assume the new value is last value plus 1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top