Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2006
    Posts
    87

    Unanswered: problem to insert a key field in another table

    hi everybody I have this case which I couldn't solve and need badly your help

    table1

    id1 field1 field2
    1 a b
    2 a c


    table2

    id1 field1 field2
    a b
    a c

    I need to update table2 on the (id1) if the value of field1 and field2 in table 1 is equal to field1 and field2 in table 2 and inserting null when there is no match:::

    I'm trying with this code but couldn't get thru

    UPDATE table2
    SET id1= COALESCE(table2.id1, 0)
    from table1
    left outer Join table2
    ON
    table1.id1=table2.id1


    thanks

  2. #2
    Join Date
    Aug 2005
    Location
    D/FW, Texas, USA
    Posts
    78
    something like this should do it for you
    Code:
    UPDATE t2
     SET t2.id1 = t1.id1
    FROM table2 t2
     LEFT JOIN table1 t1 ON t2.field1 = t1.field1 AND t2.Field2 = t1.field2

    --wayne
    SELECT * FROM Users WHERE Clue>0
    0 rows returned

Posting Permissions

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