Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need help with sequence
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

2 Posts

Posted - 01/29/2013 :  02:36:59  Show Profile  Reply with Quote

I have a column with name "CustomerNumber". I want to get increment the max value of this column by 1 and then return me the incremented number. I know we have to do this through stored procedures and sequence generators. but im not sure how exactly. please explain.

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 01/29/2013 :  02:46:15  Show Profile  Reply with Quote
the best way to deal with this is to make the column an identity one so that values will get incremented automatically
If you want to simulate it,use

SELECT @MaxID=MAX(CustomerNumber)
FROM Customers

please be aware that for batch insertions you've to generate bunch of new id values and above method wont work.
For that you need to make use of a temporary table with identity column itself.

SQL Server MVP

Go to Top of Page

Aged Yak Warrior

940 Posts

Posted - 01/29/2013 :  21:24:30  Show Profile  Reply with Quote
It's highly likely you really want to use an "Identity" column for this, or, in SQL 2012, an actual SEQUENCE object which is even better. If you intend to use the number and write it back then be aware that Visakah's method only really works reliably for single user. With multiple users (connections actually) you either end up gummed up serialised behind locks or reusing numbers depending on your isolation model.
Go to Top of Page

Starting Member

2 Posts

Posted - 01/30/2013 :  00:23:17  Show Profile  Reply with Quote

Can u explain how to do it step by step?
Go to Top of Page

Flowing Fount of Yak Knowledge

2167 Posts

Posted - 01/30/2013 :  07:06:16  Show Profile  Reply with Quote

How to ask:

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000