Results 1 to 7 of 7

Thread: SQL Update

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    UK
    Posts
    147

    SQL Update

    I have two tables A and B each table has three fields 1,2 and 3.
    What i need to do is update table A field 3 with the value of table B field 3 where A.1 = B.1 and A.2 = B.2 The problem is i have know idea of the SQL statment i need to achive this.
    Mik706

  2. #2
    Frenzied Member Lightning's Avatar
    Join Date
    Oct 2002
    Location
    Eygelshoven
    Posts
    1,611
    In case of msSQL
    VB Code:
    1. update TableA set TableA.FieldC =  TB.fieldC from TableA TA, TableB TB where TA.PrimKey = TB.ForeignKey
    VB6 & C# (WCF LINQ) mostly


    If you need help with a WPF/WCF question post in the NEW WPF & WCF forum and we will try help the best we can

    My site

    My blog, couding troubles and solutions

    Free online tools

  3. #3
    Fanatic Member doofusboy's Avatar
    Join Date
    Apr 2003
    Posts
    526
    Try something like this:

    UPDATE Table_A
    SET Table_A.Field_3 = Table_B.Filed_3
    WHERE Table_A.Field_1 = Table_B.Field_1
    AND Table_A.Field_2 = Table_B.Field_2
    Do canibals not eat clowns because they taste funny?

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    UK
    Posts
    147
    doofusboy, that is the method i have tried but it just requests a value for TableA.Field_1.

    I forgot to add that i am using Access
    Mik706

  5. #5
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    Make sure the criteria would return only one record from table B.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    UK
    Posts
    147
    I dont want to update just one record, i want to update all the matching records.
    Mik706

  7. #7
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    "but it just requests a value for TableA.Field_1."
    Then Field_1 is not a fieldname in TableA


    Try this MS Access syntax

    Code:
    UPDATE TableA 
    INNER JOIN TableB ON TableB.Field1 = TableA.Field1 And TableB.Field2 = TableA.Field2
    SET TableA.Field3 = TableB.Field3;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width