How to genrate automaticlly empid like gt001

Answers were Sorted based on User's Feedback



How to genrate automaticlly empid like gt001..

Answer / vijayalakshmi u

Create Table emp
(
dbID int NOT NULL IDENTITY (1,1) PRIMARY KEY,
customerNumber NVARCHAR(100) auto_increment,
Name Varchar(100)
)

Create function CustomerNumber (@id int)
returns varchar(10)
as
begin
DECLARE @ret varchar(10) ;
select @ret='gt' + right('0000' + convert(varchar(10), @id), 4)
RETURN @ret
end


create trigger emp_insert on emp
after insert as
update emp
set
emp.customerNumber = dbo.CustomerNumber(emp.dbID)
from
emp inner join
inserted on emp.dbID= inserted.dbID

Is This Answer Correct ?    2 Yes 0 No

How to genrate automaticlly empid like gt001..

Answer / trainedforjob

create a identity column and create a computed column which will br 'gt' concatenate identity column

Is This Answer Correct ?    0 Yes 0 No

How to genrate automaticlly empid like gt001..

Answer / 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

How to genrate automaticlly empid like gt001..

Answer / pravati

INSERT INTO TABLE NAME(EMPLOY ID) VALUES('gt_001')

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL Server Interview Questions

How to loop through result set objects using mssql_fetch_array()?

0 Answers  


What happens if null values are involved in boolean operations?

0 Answers  


Name 3 of the features that the sql server built-in function loginproperty performs on standard logins? : sql server security

0 Answers  


in the physical file layout, where should the transaction log be stored in relation to the data file? : Sql server administration

0 Answers  


What is key set driven?

0 Answers  






What is sql server profiler?

0 Answers  


What is the difference between DataRow.Delete() and DataRow.Remove()?

0 Answers  


What is difference between inner join and join?

0 Answers  


How can windows applications connect to sql servers via odbc?

0 Answers  


what is differece between union and union all

6 Answers  


How to Get the last identity value used

4 Answers  


can any body tell me how to know the password of current user in sql server

0 Answers   Crea, HCL,


Categories