moayyad
asked on
how to get the value of the a specific field in the last record?
Hello,
i think to make the ID field as a sequential number. and i want to give it the last ID+1 , so, how can i get the last record in a specific table?.
i succeeded to get the last record index by using:
table1.RecordCount
but now i want to get the value of the field 'id' for the last record table1.RecordCount !.
would u help me please?
i think to make the ID field as a sequential number. and i want to give it the last ID+1 , so, how can i get the last record in a specific table?.
i succeeded to get the last record index by using:
table1.RecordCount
but now i want to get the value of the field 'id' for the last record table1.RecordCount !.
would u help me please?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
oops, wrong link, it was https://www.experts-exchange.com/questions/21866456/Auto-increment-key-violation.html
The above idea will fail. You shouldn't rely on RecordCount or last record value as you delete a record id will be duplicated and in RDBMS like MSSQL there is nothing like last record. You must use a query that will do this job.
e.g. select isnull(max(id),0)+1 as newid from yourtable
e.g. select isnull(max(id),0)+1 as newid from yourtable
ASKER
atul_parmar,
are you sure from this statment ?
because i had a general error in SQL change it to active?
select isnull(max(id),0)+1 from customer;
are you sure from this statment ?
because i had a general error in SQL change it to active?
select isnull(max(id),0)+1 from customer;
isNull is an inBuild sql-function,
which must be supported by the sql-database
(guess its only for interbase/firebird) -> (the oracle dependant is NVL())
so it would be nice, if you could tell us which database u use,
so that we are able to give specific advice
meikl ;-)
which must be supported by the sql-database
(guess its only for interbase/firebird) -> (the oracle dependant is NVL())
so it would be nice, if you could tell us which database u use,
so that we are able to give specific advice
meikl ;-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
my database is ms access. and this work with me thanks alot (f).
what for a database do you use?
meikl ;-)