update sql relating a column with external value

1

Good morning, I'm having a hard time doing an SQL Server update. I have the following situation:

Table 1

ID
Codigo

Table 2

ID
Nome

And I have an excel file like this:

Excel

Codigo
Nome

I need to update the Name column of Table 2 , with excel data, what would querry be in this situation?

I've tried this:

SELECT *
FROM Tabela2 F
FULL JOIN Tabela1 M ON F.id = M.codigo
    
asked by anonymous 25.09.2018 / 14:40

2 answers

0

I think you're looking for inner join :

SELECT T2.Nome,
       T1.Codigo
FROM Table1 T1 INNER JOIN Table2 T2 ON T1.ID = T2.ID
WHERE --outras condições

To enter the excel file data:

SELECT * INTO nome do arquivo
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
    'Excel 12.0; Database=nome do arquivo.xlsx', [página$]);

If you are looking for an update by joining the two tables:

UPDATE T2
SET Nome = 'NOME'
FROM [Tabela 2] T2
INNER JOIN [Tabela 1] T1 on T2.ID = T1.id
WHERE T2.Codigo = 'CODIGO'
    
25.09.2018 / 14:46
1

I did it with the following situation

update Tabela 2
set Nome = '**NOME**'
from Tabela 2 A
INNER JOIN Tabela 1 B on B.ID = A.id
where B.Codigo = '**CODIGO**'

As the values are in an excel file I need to update a situation in a SQL table, I'll need to manually do this querry for every update I need to update. The values NAME , CODE are in excel. For the excel itself I can make a CONCATENATE structure, which will kind of prepare the querrys. Thanks for the tips, and for the attention!

    
25.09.2018 / 14:55