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 real and float literal values are rounded?

0 Answers  


What command is used to rename the database?

0 Answers  


What are the advantages of using stored procedures in sql server?

0 Answers  


What is the difference between system objects and user objects?

0 Answers   HCL,


What are the aggregate and scalar functions?

0 Answers  






What is mean by clustered index and non clustered index, give syntax of creation? : sql server database administration

0 Answers  


What are the type of joins? When do we use Outer and Self joins?

3 Answers  


How to convert a table data in XML format in sql server?

0 Answers  


What stored by the master?

0 Answers  


hi ..i am working as a sql dba.....now i want to learn more about t-sql..... is it possible to learn online.... plz refer any site ..thankq

0 Answers   IBM,


Can you explain about buffer cash and log cache in sql server?

0 Answers  


Explain about the command-line tool SQLCMD?

0 Answers  


Categories