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
 General SQL Server Forums
 New to SQL Server Programming
 Update Statement

Author  Topic 

dazza5621
Starting Member

7 Posts

Posted - 2009-04-26 : 03:56:13
Hi, I am trying to use and update statement based on data in a second table however, when I run it rather than update just 1 record it updates the whole table, can anybody help. Thanks in anticipation

UPDATE table1
SET Guid = '123-123-123'
WHERE EXISTS(SELECT T0.[Guid] FROM [table2] T0 WHERE T0.[Guid] = '234-234-234' and T0.[Name] LIKE 'test%')

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-26 : 04:05:50
You are missing a relation between table and table2.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

dazza5621
Starting Member

7 Posts

Posted - 2009-04-26 : 04:23:55
Thanks, at which point should I insert this after the Update?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-26 : 04:27:12
UPDATE table1
SET Guid = '123-123-123'
WHERE EXISTS(SELECT T0.[Guid] FROM [table2] T0 WHERE T0.[Guid] = '234-234-234' and T0.[Name] LIKE 'test%'
and table1.somecol = t0.somecol)


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

dazza5621
Starting Member

7 Posts

Posted - 2009-04-26 : 04:33:05
Just the job, many thanks
Go to Top of Page
   

- Advertisement -