Update problem

  • Hi

    I have an update which works fine.

    UPDATE Table1

    SET T1.col1 = T2.Name

    FROM dbo.Table1 T1, dbo.Table2 T2

    WHERE T1.Fname = T2.Fn AND T1.Last_name = T2.LN

    But for some recs in T1 there are multiple matching T2 rows.In this case I would like to get the info from the last record in T2. Hot can I achieve this.

    As of now it gets the matching from first record.

    Thanks

  • [font="Arial"]

    Hello

    There are several ways to go about this problem. However, it would help to know if there are any other fields in T2.

    For example, does T2 have an identity column? If it does, say it was named rowId. If so you could use the max(rowId) in a subquery to qualify the latest record for a first/last name condition.

    Can you give us more information about the T2 table? If it doens't have a identity column, is it permitted to add one to it?

    Regards,

    Terry

    [/font]

  • pzmrcd (6/13/2008)


    But for some recs in T1 there are multiple matching T2 rows.In this case I would like to get the info from the last record in T2.

    Define "last".

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

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

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