How to genrate automaticlly empid like gt001

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain cdc and sql injection?

541


Which is better statement or preparedstatement?

514


How do you use a subquery to find records that exist in one table and do not exist in another?

541


Call by value and call by reference in procedure and function, with NOCOPY.

827


What is the difference between system objects and user objects?

699






What do you mean by recursive stored procedure?

502


How to make a column nullable?

589


Can group by be used without aggregate functions?

466


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

529


What is ddl and dml commands?

505


What is the difference between ‘having’ clause and a ‘where’ clause?

538


What happens if ntwdblib.dll is missing on your machine?

627


Do you know what is openxml in sql server?

610


What is the web service used for reporting services?

98


How can you tell if a database object is invalid?

607