SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Update problem


Update problem

Author
Message
pzmrcd
pzmrcd
SSC-Addicted
SSC-Addicted (455 reputation)SSC-Addicted (455 reputation)SSC-Addicted (455 reputation)SSC-Addicted (455 reputation)SSC-Addicted (455 reputation)SSC-Addicted (455 reputation)SSC-Addicted (455 reputation)SSC-Addicted (455 reputation)

Group: General Forum Members
Points: 455 Visits: 87
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
tbeadle
tbeadle
SSChasing Mays
SSChasing Mays (621 reputation)SSChasing Mays (621 reputation)SSChasing Mays (621 reputation)SSChasing Mays (621 reputation)SSChasing Mays (621 reputation)SSChasing Mays (621 reputation)SSChasing Mays (621 reputation)SSChasing Mays (621 reputation)

Group: General Forum Members
Points: 621 Visits: 206

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

RBarryYoung
RBarryYoung
SSC Guru
SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)SSC Guru (55K reputation)

Group: General Forum Members
Points: 55218 Visits: 9518
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".

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search