Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2008
    Posts
    24

    Unanswered: Need help with a simple UPDATE

    Hello,

    I have 2 tables:

    tableA tableB
    --------------- ----------------------
    uniqueID int uniqueID int
    aFlag smallint field1 int
    field2 char(3)
    ...

    I need to UPDATE tableA such that the value of aFlag is 1
    if a record EXISTS in tableB with the same uniqueID.

    Thanks in advance for any input,
    chasse

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    Code:
    update tableA
    set    aFlag = 1
    where  exists( select 1 from tableB b where b.uniqueID = tableA.uniqueID )
    You'd do better not having a flag though. The best way to test to see if there is data in tableB for that id is to simply look in tableB.

  3. #3
    Join Date
    Aug 2008
    Posts
    24
    Yes, thank so much.
    I agree - it wasn't my design.
    The resulting lack of referential integrity is causing problems elsewhere -
    thus the need for this UPDATE

Posting Permissions

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