Generate and retrieving Next sequential Customerid

Posted on 2009-04-30
Medium Priority
Last Modified: 2012-05-06
There is a need for me to  list all customerid plus e next sequential CustomerId. in this table the customerid is not a primary key. I think a subquery should. How can i modify the below query to achieve this
select Distinct Customer_Id from customers
from (select MAX (Customer_Id) + 1 from customers where CUSTOMER_ID <> 999 )

Open in new window

Question by:Projack
LVL 75

Accepted Solution

Aneesh Retnakaran earned 1000 total points
ID: 24272823
select MAX (Customer_Id) + 1 from customers
SELECT Customer_id from Customers
LVL 22

Assisted Solution

dportas earned 1000 total points
ID: 24273490
What if the table is updated after you query it? What if the next inserted row gets rolled back or deleted? Your assumption about the next sequential Id may be incorrect. Whether that matters or not depends on how you are using the information.

Author Closing Comment

ID: 31576580
Thanks for your advice. It is admin moduleand only one operator use that page per time

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question