Solved

update with join

Posted on 2012-03-12
8
336 Views
Last Modified: 2012-03-12
i have written the following select

select ceb.New_LegacyCDBID
FROM   ContractExtensionBase ceb
inner join ContractBase cb
on ceb.contractid=cb.contractid
where New_LegacyCDBID  is not null
and statecode = 4 and statuscode = 5

what i want to do now is update ceb.New_LegacyCDBID  using the above join but not sure of syntax?

an helpers!

Thanks
0
Comment
Question by:ac_davis2002
8 Comments
 
LVL 13

Expert Comment

by:lee555J5
ID: 37710545
UPDATE ContractExtensionBase ceb INNER JOIN ContractBase cb
ON ceb.contractid = cb.contractid
SET ceb.New_LegacyCDBID = ???
WHERE statecode = 4 AND statuscode = 5;

You need to replace the ??? with your data and add any addition WHERE conditions.

Lee
0
 
LVL 13

Expert Comment

by:lee555J5
ID: 37710550
*additional WHERE conditions.
0
 

Expert Comment

by:Stuporman
ID: 37710552
For syntax, I always go to www.w3schools.com and go to their SQL tutorial. They have just about everything.
0
 

Author Comment

by:ac_davis2002
ID: 37710583
hi

getting the follow error

Incorrect syntax near 'ceb'.
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Expert Comment

by:Stuporman
ID: 37710600
I'm pretty sure you can't have a join clause in an update statement. I just checked both SQL Server's and Oracle's documentation and neither of them say you can. I think you just need to find a different way to identify the rows you want to update.

Are statecode and statuscode both a part of the ContractBase table?

On second examination, it looks like you are implementing table inheritance. Is that why you want to join in the update?
0
 
LVL 13

Accepted Solution

by:
lee555J5 earned 500 total points
ID: 37710606
Sorry, I had Access on the brain. Try this

UPDATE ceb
SET ceb.New_LegacyCDBID = ???
FROM ContractExtensionBase ceb INNER JOIN ContractBase cb
ON ceb.contractid = cb.contractid
WHERE statecode = 4 AND statuscode = 5;
0
 

Expert Comment

by:Stuporman
ID: 37710611
Ok, forget my comment. I see lee's syntax in SQL Server's documentation now.
0
 
LVL 25

Expert Comment

by:jogos
ID: 37710640
UPDATE ceb
SET ceb.New_LegacyCDBID = ???   -- TODO add your  newvalue here
FROM ContractExtensionBase ceb 
INNER JOIN ContractBase cb ON ceb.contractid = cb.contractid
WHERE statecode = 4 AND statuscode = 5;

Open in new window


Updated: see this was parallell posted and I wasn't first :)
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now