SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


insert problem


insert problem

Author
Message
polo.csit
polo.csit
SSC-Enthusiastic
SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)

Group: General Forum Members
Points: 117 Visits: 626
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
ps.
ps.
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3229 Visits: 3668
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
--------
1 e00001 pradeep
2 e00002 polo
3 e00003 csit
4 e00004 singh
=================================================
Is this what you want?



Pradeep Singh
Madhivanan-208264
Madhivanan-208264
SSChasing Mays
SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)SSChasing Mays (629 reputation)

Group: General Forum Members
Points: 629 Visits: 476
So you are trying to format the empno?

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=57069



Madhivanan

Failing to plan is Planning to fail
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search