Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to ganrate two autonumer in single table in sql one for rollno and second for registration no how we can do
Posted
Comments
Siva Hyderabad 11-Feb-14 5:04am    
I generate example for "0000" , "0001", "0002"...so,which type of generate..you can proceed

first generate roll number like this..
VB
1.) Right Click On the table Select Modify Table.

2.) Click on the Column you want to increment.

3.) In the column Property Window below click + of Identity Specification

4.) Make (Is Identity) from No to "Yes".

Thats It.



You can generate another way...You can write procedure like this...



SQL
Create PROCEDURE [dbo].PRocName

AS
BEGIN
	
SET NOCOUNT ON;

SELECT RIGHT(REPLICATE('0', 4) + CAST(CAST(COALESCE(MAX(autoGenerateColumnName), 0) AS INT)  AS VARCHAR), 4) dcno
  FROM
(
  SELECT TOP 1 autoGenerateColumnName
    FROM TableName
   ORDER BY sno DESC
) q;
end
else



END
 
Share this answer
 
Take a look http://www.w3schools.com/sql/sql_autoincrement.asp
 
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