Click here to Skip to main content
15,908,013 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i generate Id like ss1
and save these ids in database and next time when i insert next record then generate id like ss2 in c#
Posted

 
Share this answer
 
You can use Identity[^] property to generate consecutive numbers for each row in database. Later you can append ss to the Id value and display it in your application.
Here is a sample
SQL
CREATE TABLE #SampleTable
(
	ID INT IDENTITY(1,1),
	SampleRow VARCHAR(50)
)

INSERT INTO #SampleTable
SELECT 'Row 1' UNION ALL
SELECT 'Row 2' UNION ALL
SELECT 'Row 3' UNION ALL
SELECT 'Row 4' UNION ALL
SELECT 'Row 5' UNION ALL
SELECT 'Row 6' 


SELECT *, 'ss'+ CAST(ID AS VARCHAR) AS Display_ID FROM #SampleTable

DROP TABLE #SampleTable
 
Share this answer
 
SQL
create table RandomID(CandID as 'SS' + RIGHT(CONVERT(varchar, CourseID),5),
CourseID int IDENTITY(1,1),
ReferrerName varchar(10)
)
INSERT into RandomID VALUES('Technical')
INSERT into RandomID VALUES('Rapist')

SELECT  * FROM RandomID
 
Share this answer
 
Comments
Surendra0x2 21-Sep-12 7:37am    
Solved..

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