Hi
Try:
Update A
SET
Info1 = LEFT(TRIM(IsNull(a.info1,'') + ' ' + IsNull(b.Info1,''))255),
Info2 = LEFT(TRIM(IsNull(a.info2,'') + ' ' + IsNull(b.Info2,'')),255),
etc, etc...
FROM
Contacts a, Contacts b
WHERE A.ID = @KeeperID
AND B.ID = @DupeID
If you had multiple contacts you could create a table (linkingTable)
containing origin PrimaryContactId and SecondaryContactId, something like:
INSERT INTO LinkingTable(PrimaryContactId, SecondaryContactId) VALUES (
@KeeperId, @DupeID )
Update A
SET
Info1 = LEFT(TRIM(IsNull(a.info1,'') + ' ' + IsNull(b.Info1,''))255),
Info2 = LEFT(TRIM(IsNull(a.info2,'') + ' ' + IsNull(b.Info2,'')),255),
etc, etc...
FROM Contacts a
JOIN linkingTable l on a.ContactId = l.PrimaryContactId
JOIN Contacts b On l.SecondaryContactId = b.ContactId
John
[quoted text, click to view] "laurenq uantrell" <laurenquantrell@hotmail.com> wrote in message
news:1102971711.114234.142300@c13g2000cwb.googlegroups.com...
>I want to create a stored procedure that will merge columns from two
> rows that contain duplicated contacts.
>
> I have can easily identify the duplicates and extract the UniqueIDs as
> parameters, but I can't figure out how to construct the actual update
> SQL.
>
> @KeeperID int,
> @DupeID int
>
> Update Contacts
> SET
> a.Info1 = LEFT(TRIM(IsNull(a.info1,'') + ' ' IsNull(b.Info1,''))255),
> a.Info2 = LEFT(TRIM(IsNull(a.info2,'') + ' ' IsNull(b.Info2,'')),255),
> etc, etc...
> FROM
> (here's what I can't figure out)
> Contacts a ID = @KeeperID
> Contacts b ID = @DupeID
>