Solved

SQL Update\Set of a field in one table from the same field in a different table.

Posted on 2010-09-14
6
254 Views
Last Modified: 2012-06-21
I have a field that needs to be updated\set in Table.B from same field from Table.A.  This needs to be done with the following conditions.

I will write in kind of a  pseudo code format:

Table.B.DOCO = Table.A.DOCO
    Table.B.REF = "6F"                  
       Table.B.DATE = '09/14/2010'
          Table.A.Line = '1'

If the above finds records the Table.B.REF will need to be populated with Table.A.REF

0
Comment
Question by:SnowLapa
6 Comments
 
LVL 20

Expert Comment

by:Silvers5
ID: 33678219
You can setup a trigger in SQL, when the above conditions are met it will insert the record in table A
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 33678225
0
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 200 total points
ID: 33678254
If I understand your requirements this is an update you need to run, not a need to keep them in sync continuously.  If so, this should do the trick.

update b
set ref = a.ref
from tableb b
join tablea a
  on b.doco = a.doco
where b.ref = '6F'
  and b.[date] = '2010-09-14' -- changed to non-ambiguous format
  and a.line = '1'

0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

by:SnowLapa
ID: 33678257
I am not very familiar with triggers and I think the learning curve would be to great.  I am a little more familiar with standard SQL statements.  Something more along those line would be great.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 33678295
>>I have a field that needs to be updated\set in Table.B from same field from Table.A. <<
Don't.  That is a nighmare.  Use a SELECT instead, somthing like:
SELECT  a.ref, b.Col1, b.Col2, b.Col3, ...

FROM    TableA a

        INNER JOIN TableB b ON a.doco = b.doco

WHERE   a.line = '1'

        AND b.ref = '6F'

        AND b.date = '2010-09-14'

Open in new window

0
 

Author Comment

by:SnowLapa
ID: 33681929
Thank you all for the speedy solutions.  BrandonGalderisi solution did work with just a few tweaks.  

Once again, thank you all......
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
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…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

930 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

8 Experts available now in Live!

Get 1:1 Help Now