How to genrate automaticlly empid like gt001

Answer Posted / dipak patil

Create Table emp
(
dbID int NOT NULL IDENTITY (1,1) PRIMARY KEY,
customerNumber NVARCHAR(100) ,
Name Varchar(100)
)
GO
----------------------------------------
Create Proc Usp_InsertRecord
@EmpName Varchar(10)
As
BEGIN
Declare @MAXValue Varchar(Max),@intValue Integer
SET @MAXValue='0'
SELECT TOP 1 @MAXValue=ISNULL(customerNumber,0) From emp Order by dbID DESC
Set @intValue=Convert(Integer,Replace(@MAXValue,'Gt',''))+1
SET @MAXValue='GT' + right('0000' + convert(varchar(10), @intValue), 4)

Insert Into Emp(customerNumber,Name) Values(@MAXValue,@EmpName)
END
----------------------------------------
-- Exec Usp_InsertRecord 'RAM'

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is user-defined scalar function?

635


Determine how to use the inserted and deleted pseudo tables?

614


What are the basic functions for master, msdb, model, tempdb databases?

672


what is a correlated sub-query? : Sql server database administration

570


Define normalisation?

775






Explain what is the use of custom fields in report?

590


How to create a new login name in ms sql server?

637


Write the syntax for stuff function in an sql server?

628


What is the simplest way to create a new database in ms sql server?

625


How to deploy the Report?

97


what are the basic functions for master, msdb, model, tempdb and resource system databases? : sql server database administration

657


What is buffer cash in sql server?

720


What is tcl in sql server?

744


What is a result set object returned by odbc_exec()?

626


What are the triggers in sql?

656