Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 7,2000
»
General
»
insert problem
insert problem
Rate Topic
Display Mode
Topic Options
Author
Message
polo.csit
polo.csit
Posted Thursday, December 25, 2008 11:03 PM
SSC Rookie
Group: General Forum Members
Last Login: Wednesday, September 29, 2010 6:40 AM
Points: 45,
Visits: 502
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
Post #625732
ps.
ps.
Posted Thursday, December 25, 2008 11:27 PM
SSCrazy
Group: General Forum Members
Last Login: Thursday, May 02, 2013 2:32 AM
Points: 2,236,
Visits: 3,620
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
Post #625737
Madhivanan-208264
Madhivanan-208264
Posted Friday, December 26, 2008 2:36 AM
Old Hand
Group: General Forum Members
Last Login: Wednesday, September 12, 2012 5:17 AM
Points: 329,
Visits: 461
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
Post #625780
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.