Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Update Syntax

Posted on 2013-11-01
3
Medium Priority
?
324 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
  • 2
3 Comments
 
LVL 66

Accepted Solution

by:
Jim Horn earned 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

971 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