Solved

SQL Update Syntax

Posted on 2013-11-01
3
311 Views
Last Modified: 2013-11-01
How can I re-write the following query so that it updates the ITEMLOC.AVERAGEUNITCOST = ITEM.COSTLASTPAID where COSTLASTPAID<>0 and AVERAGEUNITCOST=0?


select item.itemnum,costlastpaid,locationnum, itemloc.averageunitcost from "ITEM"
inner join itemloc on item.itemnum=itemloc.itemnum
where costlastpaid<>0 and itemloc.averageunitcost=0
0
Comment
Question by:trbbhm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 66

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 39616951
Give this a whirl..
UPDATE ITEMLOC
SET il.AVERAGEUNITCOST = i.COSTLASTPAID
FROM ITEMLOC il
   JOIN  ITEM i on i.itemnum=il.itemnum 
WHERE costlastpaid<>0 and il.averageunitcost=0

Open in new window

0
 
LVL 29

Expert Comment

by:sammySeltzer
ID: 39616960
Update ITEM set  ITEMLOC.AVERAGEUNITCOST = ITEM.COSTLASTPAID 
 from item inner join itemloc on item.itemnum=itemloc.itemnum 

where  costlastpaid<>0 and itemloc.averageunitcost=0

Open in new window

0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 39617051
Thanks for the grade, which put me over the top for Genius in MS SQL Server.
Good luck with your project.

Jim
0

Featured Post

Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

623 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