Import Excel data to table in SQL Server (only data other than that already in the table)

Asked

Viewed 58 times

0

I just want to add different records than the ones already in the table, that is, they would only be records from Idcollaborator 10.

Dados no excel

Dados na tabela sql

  • in management studio can do import, and can use a bulk, research on this and should help

  • OK, I’ll look for

2 answers

0

There are some solutions and one of them involves using Linked server to access the spreadsheet in Excel as if it were a table. Then include lines that are in the spreadsheet and that are not part of the table.

Here is the sketch of the code:

-- código #1
INSERT into Colaboradores (colunas)
  SELECT P.colunas
    from planilha as P
    where not exists (SELECT * from Colaboradores as C where C.IdColaborador = P.IdColaborador);

Details in the article Bulk data import (Bulk load).

-4

Use Msaccess and import excel to Msaccess. Next export Msaccess to SQL. When you already have in SQL do the validations in the database before inserting

Browser other questions tagged

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