Sunday 3 September 2017

SQL Server: Update From Select Statement

SQL Server: Update From Select Statement
Description:

In this example we explain that how to update table from select statement in SQL Server. Or SQL Query to update from select statement. Or update some value from one table to another table using select query in SQL Server. Or how do I update from s select statement in SQL Server. Or update from select statement using join in SQL Server. Or update Query in SQL with Select statement.

Here in this example we update product table from one database to another database table using select statement using JOIN between both table.so how to update table from select statement with another table in SQL Server.

Syntax:

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'

Query:


UPDATE dbo.ProductBase 
set ProductBase.new_ProductCode=p.ProductCode,
ProductBase.Name=p.ProductDescription
from Product p inner join dbo.ProductBase a on a. ProductId =p.ProductId
WHERE ProductId =@ProductId;



This entry was posted in :

0 comments:

Post a Comment