Solved

Update values in a table with results from a SELECT statement

Posted on 2009-07-03
2
169 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
2 Comments
 
LVL 142

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mySql Syntax 7 44
Pivot Table for a join with partition by and over clause 7 29
Urgent help needed! Unable to to paste in query designer 29 38
Update data using formula 22 23
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

19 Experts available now in Live!

Get 1:1 Help Now