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 |
Diff between Composite key, Alternate Key, Candidate Key, Primary Key, Unique Key, Super Key, Foreign Key
What are the different authentication modes in sql server?
How to create a large table with random data for index testing in ms sql server?
What happens if an integer is too big for int date type?
What is the importance of a recovery model?
select the 3rd maximum salary from sql server database if 4 (just an example In practically I may not know the exact situation) of the highest salaries are equal.
What is the usage of sign function?
what is the difference between Delete and Truncate
4 Answers CarrizalSoft Technologies, Geo Research Centre,
Does view occupy space?
what are the limitations of parameters in a storedprocedure
Can you please explain the difference between primary keys and foreign keys?
What is SQL Server?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)