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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How extra digits are handled with numeric data type literals?

975


What are advantages of ssrs or why we should use ssrs?

139


What is the difference between row_number and dense_rank?

890


What are various limitations of the views?

1063


What is the purpose of the model database?

1024


What is a data source or ds? : sql server analysis services, ssas

1014


How to search for a string in all stored procedure in sql server?

1008


How to recreate an existing index in ms sql server?

1069


You want to implement the one-to-many relationship while designing tables. How would you do it?

967


What is the purpose of the tempdb database?

1006


What is use of except clause?

1096


How to define output parameters in stored procedures?

1033


What is Service Broker in sql server 2012?

1028


What is Federation and Federation Member?

92


How to generate create view script on an existing view?

993