You can make a select
directly in your spreadsheet:
(You will need to run the initial settings with the sp_configure)
sp_configure 'show advanced options', 1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries', 1
reconfigure
SELECT * FROM OPENROWSET ('Microsoft.ACE.OleDB.12.0',
'EXCEL 8.0;Database=C:\importacao.xlsx',
Planilha1$)
In the select above, the OPEMROWSET
will behave like a table, so you can do whatever you want, including popular the tables with the fields you want.
SELECT COD_FUN, COD_PROCEDIMENTO INTO TabelaTeste
FROM OPENROWSET ('Microsoft.ACE.OleDB.12.0',
'EXCEL 8.0;Database=C:\importacao.xlsx',
Planilha1$)
Requirements
The Server (where SQL Server is installed) must have access to the folder where your Excel file is; in the above example, "C: " is directly the server root.
Check which Provider you have installed:
Right click on top of your database -> tasks-> Import Data. In the window that opens click on avenging and choose the data source as Microsoft Excel
– Jeferson Almeida
@Jefersonalmeida, it’s not quite so. As I said earlier is the following: In the spreadsheet I have the field Dt_proc and Num_proc. These fields will be populated. There is also a field that is Id_func. For this field I need to make a Join with another table for popular, since the table that will be populated does not have this field. That is, I need to "join" two tables to popular a third. This is the imbrolho that step.
– pnet
The way q I said vc will create a new table with all the excel data and through this new table, vc can do all its joins to popular its true table, at the end of the process vc deletes the table that was created from excel.
– Jeferson Almeida
Do you say create a temp? And popular everything with excel and then popular the other table?
– pnet
That’s right, this way it becomes much easier for you to handle your data
– Jeferson Almeida