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)
 Case query?

Author  Topic 

lekfir
Starting Member

3 Posts

Posted - 2008-12-12 : 04:06:46
Hello,
I try to update Table1 basedon data in Table2

For Example:
Set Col1.Table1='OK'
Case Col2.Table1 exists in Col2.Table2


Col2.Table has ~ 1000 rows with numbers...

How can I perform this action?
Thanks!


SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-12-12 : 04:09:09
[code]UPDATE t1
SET t1.Col1 = 'OK'
FROM Table1 AS t1
INNER JOIN Table2 AS t2 ON t2.Col2 = t1.Col2[/code]

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

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2008-12-12 : 04:31:53
Update t1
set t1.col1 = 'ok'
from Table1 t1
where t1.col2 IN (select col2 from Table2)
Go to Top of Page

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2008-12-12 : 04:36:12
UPDATE t1
SET t1.col1 = 'OK'
FROM Table1 AS t1
WHERE EXISTS(SELECT col2 FROM Table2 t2 WHERE t2.col = t1.col)

Jai Krishna
Go to Top of Page
   

- Advertisement -