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?
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?
There is no secret:
update tabelaprincipal
set codBarra = temp.codBarra
from #tabelatemporaria temp
where tabelaprincipal.codProduto = temp.codProduto
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: