Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Update field in table based on row match to join?

Author  Topic 

batcater98
Starting Member

22 Posts

Posted - 2009-01-21 : 13:58:25
I am trying to update a field in a table based on the successful match to another table in a join. But it is simply updating every row - which I know is not true. What am I doing wrong.

Here is what I have now.

UPDATE event_data
SET Is_Source = 'Y', DN_Source =
FROM event_data INNER JOIN
event_data_details ON event_data.DN_Source =
event_data_details.DN_Source

What I want is for every match of event_data.dn_source to event_data_details.dn_source I want to put a character Y in the is_source field of event_data table.

Thanks,
ad.

Regards,
The Dark Knight
-Give What is Right, Not What is Left-

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-01-21 : 14:02:54

UPDATE t
SET t.Is_Source = 'Y'
FROM event_data t
INNER JOIN event_data_details m
ON t.DN_Source = m.DN_Source

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-21 : 14:03:59
i dont think there's any problem with query. it will only update those records where event_data.DN_Source =
event_data_details.DN_Source holds true
Go to Top of Page

batcater98
Starting Member

22 Posts

Posted - 2009-01-21 : 14:11:54
Thank you - that worked perfectly!

Regards,
The Dark Knight
-Give What is Right, Not What is Left-
Go to Top of Page
   

- Advertisement -