?
Solved

Generate and retrieving Next sequential Customerid

Posted on 2009-04-30
4
Medium Priority
?
247 Views
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

0
Comment
Question by:Projack
3 Comments
 
LVL 75

Accepted Solution

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

Assisted Solution

by:dportas
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.
0
 

Author Closing Comment

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

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