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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 auto number in stored procedure

Author  Topic 

noblemfd
Starting Member

38 Posts

Posted - 2014-04-09 : 19:15:00
How do I auto number in stored procedure (spCustomer) from this table. It will auto-generate CustID and CustCode
CREATE TABLE tblCustomer
(
CustID BIGINT NOT NULL PRIMARY KEY,
CustCode NVARCHAR(10) NOT NULL,
CustName NVARCHAR(100) NOT NULL,
CustPhone NVARCHAR(15) NULL
)

CustID | CustCode | CustName | CustPhone
1 |Cust-00001 | Adeleye | 08055766
2 |Cust-00002 | Oluseyi | 08088664
3 |Cust-00003 | Obafemi | 08066666

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-04-09 : 19:16:47
Use the IDENTITY option for the column and then use SCOPE_IDENTITY() after the insert.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2014-04-10 : 04:29:55
Also refer this http://beyondrelational.com/modules/2/blogs/70/posts/19496/generating-alphanumeric-serial-numbers.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -