Horje
How do I UPDATE from a SELECT in SQL Server? Code Example
How do I UPDATE from a SELECT in SQL Server?
UPDATE     Table_A SET     Table_A.col1 = Table_B.col1,     Table_A.col2 = Table_B.col2 FROM     Some_Table AS Table_A     INNER JOIN Other_Table AS Table_B         ON Table_A.id = Table_B.id WHERE     Table_A.col3 = 'cool'
How do I UPDATE from a SELECT in SQL Server?

In SQL Server 2008 (or newer), use MERGE

MERGE INTO YourTable T
   USING other_table S 
      ON T.id = S.id
         AND S.tsql = 'cool'
WHEN MATCHED THEN
   UPDATE 
      SET col1 = S.col1, 
          col2 = S.col2;
Alternatively:

MERGE INTO YourTable T
   USING (
          SELECT id, col1, col2 
            FROM other_table 
           WHERE tsql = 'cool'
         ) S
      ON T.id = S.id
WHEN MATCHED THEN
   UPDATE 
      SET col1 = S.col1, 
          col2 = S.col2;




Sql

Related
sql use with to get value counts and percentages Code Example sql use with to get value counts and percentages Code Example
sql server remove 0 from left Code Example sql server remove 0 from left Code Example
how to get last element sql Code Example how to get last element sql Code Example
soql update query Code Example soql update query Code Example
postegresql update to null Code Example postegresql update to null Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7