Domanda

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$]')
È stato utile?

Soluzione

I encountered this problem to, this because of default tables values, for string values this would be for example a varchar(50) where i needed a varchar(120)

My solution there was to place the excel into a csv file (standard save in excel) and then use the sql Import/export UI to import the files into a table. During this process you can see all the default values and then via the advanced tab change these values to your own preferences.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top