Solved

SQL Update Syntax

Posted on 2013-11-01
3
308 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 65

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 65

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how the fundamental information of how to create a table.

752 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