×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Update SQL

Update SQL

Update SQL

(OP)
I have an issue with my update SQL.

Table A is existing EMPLOYEES table with 10000+ records.
Table B is a EMPTEMP table where I have loaded all the information for the employees I need to update (only about 1161 records).

My SQL Update statement:

Update employees em SET (lname, startdate, enddate, emercontact) = (select lname, startdate, enddate, emergency_contact from emptemp et where em.emplid = et.employeeid)

That sql will update all 10000+ records and make all other records and fields NULL besides the 1161 records.

My question is what am I doing wrong?

thank you

noob

RE: Update SQL


Try:

CODE

Update employees em
   SET (lname, startdate, enddate, emercontact)
     = (select lname, startdate, enddate, emergency_contact
          from emptemp et where em.emplid = et.employeeid)
WHERE EXISTS
       (select 'Yes'
          from emptemp et where em.emplid = et.employeeid)
3eyes

 

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 

RE: Update SQL

What platform are you working in?

Denny
MVP
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

My Blog

RE: Update SQL

(OP)
Thank you, LKBrwnDBA; I will try that.

mrdenny, I'm working in Oracle 10g.

RE: Update SQL

(OP)
it doesn't work. :(

It's updated 2000+ records instead of the 1161. Any ideas why all this is happening?

thks!

RE: Update SQL

noob999,

WHAT doesn't work?  You've had 2 suggestions so far.

And HOW does it not work?  Any messages?  What results are you getting?  What can you tell us?

--

"If to err is human, then I must be some kind of human!" -Me

RE: Update SQL

Did you try my suggestion ?

RE: Update SQL

You'll be rolling back, won't you, so you can undo these changes you made.. Or is that not important ?

Tao Te Ching Discussions : Chapter 9 (includes links to previous chapters)
What is the nature of conflict?

RE: Update SQL

(OP)
Yes. I have rollback. Both did not work ... for some reasons it updated 1355 records and not just the 1161 that I wanted to. There were no errors or messages. The only problem is the number of records it updated.

RE: Update SQL

(OP)
No. I have checked for duplicates.

RE: Update SQL

(OP)
sorry for the late reply; was out of office the remaining of last week.
I will try those and post the results later today.

Thanks for all your help.

RE: Update SQL

(OP)
SELECT COUNT(*) FROM emptemp;

1161 records

SELECT COUNT(DISTINCT employeeid) FROM emptemp;

1161 records

SELECT COUNT(*) FROM employees WHERE emplid IN (SELECT employeeid FROM emptemp):

1161

SELECT COUNT(DISTINCT emplid) FROM employees WHERE emplid IN (SELECT employeeid FROM emptemp):

1161

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close