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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

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

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
SnowLapa
Asked:
SnowLapa
1 Solution
 
Michel SakrCommented:
You can setup a trigger in SQL, when the above conditions are met it will insert the record in table A
0
 
BrandonGalderisiCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
SnowLapaAuthor Commented:
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
 
Anthony PerkinsCommented:
>>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
 
SnowLapaAuthor Commented:
Thank you all for the speedy solutions.  BrandonGalderisi solution did work with just a few tweaks.  

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

Featured Post

Industry Leaders: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now