I have a script that creates a table as well as a column for tracking the filename that is responsible for the import.
select *, 'file1.xls' as 'Filename'
into dbo.SQLServerTable
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=D:\testing.xls;HDR=YES','SELECT * FROM [Sheet1$]')
I then need to perform additional imports which have different filenames. I don't believe this statement is syntactically correct and it is preventing the import.
INSERT INTO dbo.SQLServerTable
Select *, 'File2.xlsx' as 'FileName'
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=D:\Convert\Converted\File2.xlsx;HDR=YES', 'SELECT * FROM [Worksheet$]')
SELECT INTOcreates a table with columns of a certain VARCHAR length. When you import second file some data in that file exceed that length. You can try eitherCREATE TABLEin advance with VARCHAR(max) columns or try setting Registry optionHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Access Connectivity Engine\Engines\Excel\TypeGuessRowsto 0 So excel would guess column type based on entire column and not just first 8 rows