Click here to Skip to main content
15,904,023 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to get (max + 1) value from SQL Data Base, is there any query to get it?
I have maximum 9 in reg_num column. But I need 10 what query should I use.

What I have tried:

select MAX (reg_num) from Student_Details
select MAX+1 (reg_num) from Student_Details
Posted
Updated 29-Mar-16 0:28am

SQL
select MAX(reg_num) + 1 from Student_Details


If you are using this method to assign id's to the students then don't do it this way. Use an IDENTITY column on your database table
 
Share this answer
 
SQL
select max ( reg_num) + 1 from Student_Details 
 
Share this answer
 
Comments
CHill60 29-Mar-16 6:28am    
If my post deserved a 5 vote then this certainly did NOT deserve a 1. Countered
Karthik_Mahalingam 29-Mar-16 7:16am    
thank you :)
Basically 'MAX' return maximum from a given column, if you want to get a next maximum number then you can get it using MAX+1
But there may be problem when multiple read, so it is recommended to use AutoIncrement(Identity seed) features of SQL
to get MAX auto increment number from table you can use below query
SELECT IDENT_CURRENT('table_name');
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900