Solved

Update values in a table with results from a SELECT statement

Posted on 2009-07-03
2
174 Views
Last Modified: 2012-05-07
I have a receipts table that contains a portion of information. I need to perform an update on this table where...

1) Table "A" is the table I need to update.
2) Table "B" contains values that are used in a caculation with values from table "B"

For example, table "A" contains:

receipt_id
receipt_amt
link_relationship_code

Table "B" contains:
link_relationship_code
hours_worked
hourly_rate

What I need to be able to do is update table "A" where

1) A.link_relationship = B.link_relationship

and set

1) A.value1 = a.receipt_amt  * B.hours_worked
2) A.value2 = a.receipt_amt  / B.hourly_rate

Any help would be appreciated.

Direct SQL or stored procedure are good. This is a SQL Server 2005 release.

0
Comment
Question by:bryan_z
[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 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24774279
you mean:
UPDATE a
   SET value1 = a.receipt_amt * b.hours_worked
     , value2 = a.receipt_amt / b.hourly_rate
  FROM table_A a
  JOIN table_B b
    ON A.link_relationship = B.link_relationship

Open in new window

0
 

Author Closing Comment

by:bryan_z
ID: 31599666
Well that was nifty cool and simple! Thanks! Worked Perfectly.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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 I will describe the Backup & Restore 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.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

705 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