We help IT Professionals succeed at work.

SQL Question - Need to do some kind of batch update from one table to another based on onlly one condition.

netadmin2004
netadmin2004 asked
on
502 Views
Last Modified: 2008-01-09
I have just created and released a new sale view in my database. I have already moved all my data into the new table, but one of my users decided it was a good idea to use an old field for data that wasn't suposed to go there. Needless to say I now need to move just the data in the one old field for her into the ne wtable. Luckily all the IDs are the same so this should just be a matter of getting the statement down with the right join info.

I'm guessing I would need "something" like below though I don't know too much about joing with updates:

UPDATE NEWSALE A1 SET A1.DESIGNNAME = A2.DESIGNNOTES WHERE A1.ACCOUNTMANAGER='Sales Persons ID' INNER JOIN OLDSALE A2 ON (A1.SALEID=A2.SALEID)
Comment
Watch Question

UPDATE NEWSALE SET DESIGNNAME = DESIGNNOTES FROM OLDSALE A2 INNER JOIN NEWSALE A1 ON A2.SALEID = A1.SALEID AND A1.ACCOUNTMANAGER = 'Sales Persons ID'

Author

Commented:
Thanks that is exactly what I needed from what I wrote however I completely forgot I don't have the accountmanagerid in both sales tables. Crap!

I do have a contact table that has the accountmanagerid and the contactid fields are in both sale table. Is it possible to do some type of three way join? I would have no idea how to get what I need done otherwise :(.

Author

Commented:
Is it possible to create a join using 3 tables to get the info I need? If not is there some other option I should use that you could reccomend?
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Awesome!!! Here's what my statement ended up looking like:

UPDATE PP_SALES SET DESIGNNAME = DESIGNNOTES FROM SALE A2 INNER JOIN PP_SALES A1 ON A2.SALEID = A1.PP_SALESID
INNER JOIN CONTACT A3
ON A1.CONTACTID = A3.CONTACTID
WHERE A3.ACCOUNTMANAGERID = 'U6UJ9A000007'

Thanks so much!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.