Update with select in time table

Asked

Viewed 1,940 times

2

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

How do update with select in the temporary table?

  • Example of update from: http://answall.com/a/65182/14584. The difference between a temporary table and a regular table is only the prefix # (temporary local) or ## (global temp) in table name. Example: #tabela_temporaria_local. Try to build your commands and edit your question with the specific problems encountered.

2 answers

2

It’s no secret:

update tabelaprincipal
set codBarra = temp.codBarra
from #tabelatemporaria temp
where tabelaprincipal.codProduto = temp.codProduto

0

Raimundo,

To perform an "UPDATE" statement with a temporary table, you will need to link the information between the table that should be updated (I believe that in your case the ideal is to use the "Product").

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:

https://msdn.microsoft.com/pt-br/library/ms177523.aspx

Browser other questions tagged

You are not signed in. Login or sign up in order to post.