struggling with update query based on inner join in SQL 2008 (1 Viewer)

joe789

Registered User.
Local time
Today, 08:05
Joined
Mar 22, 2001
Messages
154
Hi Folks,

I have been struggling with a query that should not be this difficult ... it is essentially updating a value based on a inner join ... any help would be greatly appreciated:

Table1
LastName
FirstName
DateOfBirth
UniqueID

Table2
LastName
FirstName
DateOfBirth
UniqueID

Basically, I want to update the value in Table1.UniqueID with the value in Table2.UniqueID based on Table1.LastName = Table2.LastName AND Table1.FirstName = Table2.FirstName AND Table1.DateOfBirth = Table2.DateOfBirth

This is what I have tried including modifications of it from the help in various areas of the web and SQL itself and it just doesn't work:

update Table1 set UniqueID = Table2.UniqueID
from Table1 Table2
inner join Table2 on
Table1.LNAME = Table2.LNAME
Table1.FNAME = Table2.FNAME
Table1.DOB = Table2.DOB

The result just doesn't work it renders some type of incorrect syntax when I cannot find any instances of any type?

Thanks!
 

WayneRyan

AWF VIP
Local time
Today, 08:05
Joined
Nov 19, 2002
Messages
7,122
Joe,

Code:
update Table1 
set    Table1.UniqueID = Table2.UniqueID
from   Table1, Table2
Where  Table1.LNAME = Table2.LNAME And
       Table1.FNAME = Table2.FNAME And
       Table1.DOB = Table2.DOB

Wayne
 

SQL_Hell

SQL Server DBA
Local time
Today, 08:05
Joined
Dec 4, 2003
Messages
1,360
or

Code:
UPDATE Table1 
SET UniqueID = Table2.UniqueID
FROM Table1
INNER JOIN Table2 ON
Table1.LNAME = Table2.LNAME AND
Table1.FNAME = Table2.FNAME AND
Table1.DOB = Table2.DOB
 

Users who are viewing this thread

Top Bottom