Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Update problem Expand / Collapse
Author
Message
Posted Friday, June 13, 2008 1:58 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, January 15, 2014 3:17 PM
Points: 61, 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
Post #517041
Posted Friday, June 13, 2008 2:13 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, October 23, 2008 1:43 PM
Points: 89, 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
Post #517049
Posted Saturday, June 14, 2008 1:16 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Friday, March 28, 2014 2:25 PM
Points: 9,902, Visits: 9,479
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."
Post #517194
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse