How to genrate automaticlly empid like gt001
Answers were Sorted based on User's Feedback
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 |
create a identity column and create a computed column which will br 'gt' concatenate identity column
Is This Answer Correct ? | 0 Yes | 0 No |
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 |
Answer / pravati
INSERT INTO TABLE NAME(EMPLOY ID) VALUES('gt_001')
Is This Answer Correct ? | 0 Yes | 0 No |
What is a Stored Procedure?
how do you determine the Load performance of any query in sql server {example how do u determine performance of a select stmnt which returns Dynamically many no of records ... some times 100,1000,10000 etc., }
Why union all is faster than union?
hw you create table in sql using existing table and variable should be in specific order given ex : in old table empid empname empsal empage empbirthdate empaddrs like is there in new table we need it as EX: exmpname empage empaddrs empid empbirthdate like we want hw we create this as a table not view or nt reporting
What are the Advantages of using CTE in sql server?
What is mssql?
write a query for list of owner who are having multiple bikes in below table 1 shanker pulsar 2 shanker Honda 3 shanker car 4 Balu pulsar 5 Balu Honda 6 Balu car 7 Shyam pulsar 8 Jaya Honda 9 Deepa car 10 vasu car
How many types of stored procedures are there in sql server?
what is spatial nonclustered index
What is the maximum number of instances in 32 bit and 64 bit sql server 2012?
Which table keeps the locking information?
What should we do to copy the tables, schema and views from one SQL Server to another?