UPDATE, MERGE or table-valued function UDF?

  • Hi,

    I'm confused how to solve this:

    Using UPDATE, MERGE, table-valued UDF or what?:w00t:

    I know using a cursor is possible but there are disadvantages...

    tblA

    colA1 colA2 colA3

    =======================

    C 15 NULL

    D 17 NULL

    G 18 NULL

    L 19 NULL

    R 20 NULL

    tblB (the lookup table)

    colB1 colB2 col3

    =======================

    28 15 1

    34 17 1

    35 18 1

    36 18 0

    37 18 0

    42 19 1

    43 20 0

    44 20 1

    To do:

    Find in tblB the lines with col3 = 1 (exists only once for same colB2-value),

    Then UPDATE tblA colA3 with value colB1. RI exists on colB2 = colA2

    --
    candide
    ________Panta rhei

  • It is a simple UPDATE --

    UPDATEtblA

    SET colA3 = colB1

    FROM tblB

    WHERE colA2 = colB2

    AND colB3 = 1

    ;

  • thx,

    you saved my day 😀

    --
    candide
    ________Panta rhei

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply