Reputation: 13
I have a some data in an excel sheet in the form of a table. I want to run an sql query on that data. I am okay to use the data raw from the csv.
Is it possible to create a temporary view or table using that data within the query itself. I don't want to create a separate table for this excel data.
Upvotes: 0
Views: 16714
Reputation:
For SQL Server 2008 and above you can use OPENROWSET
In simplest form it will look like this:
SELECT * FROM OPENROWSET(BULK 'data.csv', SINGLE_CLOB) AS DATA;
Just remember to specify full file path.
Upvotes: 2
Reputation: 6417
There are a bunch of answers for this already... Have you searched?
You want to do something like this;
Select *
into [temp_table$]
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\spreadsheet.xls;HDR=YES;IMEX=1',
'SELECT * FROM [SHEET1$]')
Like in this question: Get Excel sheet into temp table using a script
Upvotes: 2