Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Does the unique constraint create an index?

991


How can I check if a view exists in a sql server database?

984


Can I save my report as html, excel or word? : sql server management studio

908


How to enable/disable indexes?

1016


What are dml triggers and types of dml triggers?

924


New concepts of sql server 2005 use in your project.

2305


What is the current limitation of the size of SQL Azure DB?

124


Can foreign key be deleted?

873


What is model database in sql server?

1004


How to concatenate two strings in SQL Server.

1082


What happens to a statement batch if there is a compilation error?

900


Differentiate between ms sql server reporting services vs crystal reports?

855


How can you insert null values in a column while inserting the data?

1213


What is the difference between system objects and user objects?

1103


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

994