December 25, 2008 at 11:03 pm
Hai all,
in insert the data
empid empcode ename
1 0 a
2 0 b
3 0 c
4 0 d
5 0 e
but i want insert the data
empid empcode ename
1 e00001 a
2 e00002 b
3 e00003 c
4 e00004 d
5 e00005 e
......
.......
10000 e10000 z
here empcode is the automatic insert the record.how it is possible
December 25, 2008 at 11:27 pm
you can use trigger in this scenario. I'm assuming empid is not an identity column and u're manually inserting data in that column.
===================================
create table employees
(
empid int,
empcode varchar(10),
ename varchar(100)
)
create trigger trg_empCode
on Employees
after insert
AS
update employees set employees.empcode= 'e'+right('0000'+cast(inserted.empid as varchar),5) from inserted
INNER JOIN employees on employees.empid=inserted.empid
insert into employees(empid, ename)
select 1, 'pradeep'
insert into employees (empid, ename)
select 2,'polo'
union all
select 3, 'csit'
union all
select 4, 'singh'
select * from employees
OUTPUT
--------
1e00001pradeep
2e00002polo
3e00003csit
4e00004singh
=================================================
Is this what you want?
December 26, 2008 at 2:36 am
So you are trying to format the empno?
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=57069
Failing to plan is Planning to fail
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply