Update with select in temp table

2

Galera, I need to create a temporary table with 2 fields (codProduct and codBarra), and with these temporary table records, I need to update on my main table.

How do I update with select in temporary table?

    
asked by anonymous 11.06.2015 / 14:15

2 answers

2

There is no secret:

update tabelaprincipal
set codBarra = temp.codBarra
from #tabelatemporaria temp
where tabelaprincipal.codProduto = temp.codProduto
    
11.06.2015 / 17:32
0

Raimundo,

To perform an "UPDATE" statement with a temporary table, you will need to link the information between the table to be updated (I believe you should ideally use the "codProduct").

Below is a T-SQL script for you to adapt to your need:

UPDATE TB_PRODUTO SET 
    codBarra = TMP.codBarra
FROM #TB_AUXILIAR AS TMP
INNER JOIN TB_PRODUTO AS UPD
ON UPD.codProduto = TMP.codProduto;
GO

For more information see:

link

    
19.06.2015 / 19:25