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 implicit cursors?

547


What is key set driven?

530


Is oracle faster than sql server?

549


As a general practice, it is recommended to have dbo be the owner of all database objects however, in your database you find number of tables owned by a user other than dbo, how could you fix this?

615


What is difference between cte and view?

517






Explain database normalization?

643


List the types of recovery model available in sql server?

501


What is multi-statement table-value user-defined function?

529


What are the differences between substr and charindex in sql server.

487


What does normalization do to data?

534


What is index, cluster index and nonclustered index?

508


What is difference between inner join and full join?

540


How to check parameter value in stored procedure sql server?

456


What is meant by referential integrity?

581


Do you know how to implement service broker?

531