SQL Server If statement to update table value

I'm trying write a routine in SQL Server that, when run, would traverse specified tables and, if a specific column contains a value, update another value. In pseudo code:

 select * from table1
 if column1 = true
 {
     update table2.column1 with value where table2.column2.value = table1.column2.value
 }

Basically, traverse table1 and if the value in a specific column is true, update the value of another table's column1 where that row's column2 matches table1's column2

Thanks

Answers


You don't need the IF, just use a WHERE clause:

UPDATE T2
SET t2.Column1 = 'blah'
FROM Table2 t2
INNER JOIN Table1 t1
   ON t1.value = t2.value
WHERE t1.column1 = 'True'

Need Your Help

Compass CSS framework - using Bootstrap with SASS

ruby twitter-bootstrap sass compass

I want to use Bootstrap with SASS, but I can't find any tutorials or explanation how one can use Bootstrap with SASS. The only thing I find is installatio trough a ruby gem:

contains in linq query

c# linq entity-framework

Hi i am using entity framework and LinQ. I have a table objects called users . i have a list called userids. i have to find all users where ids contains in the string. I have to do following operat...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.