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

What is reference section?

588


how you can deploy an ssrs report?

131


Which are the olap features?

655


What is difference between aggregate and analytic function?

570


Explain about analysis services?

661






what is raid? : Sql server database administration

632


Which trace flags are enabled in sql server?

593


What do you mean by cardinality?

575


Explain differentiate between a having clause and a where clause?

591


What is raid, and how it can influence database performance?

667


What are the 7 disadvantages to a manual system?

593


Name some of the open source software that you can use in alternative to SSR?

121


What does man by sql wildcard characters in sql server?

620


What are relationships and mention different types of relationships in the dbms

638


Where sql server usernames and passwords are stored in a sql server?

574