NewStudent
NewStudent

Reputation: 157

How to deal with Excel file in SQL query?

i had a problem .... i have and old excels files and i want to save them into SQL database ... MY Q is : if i want to do for example in .xls from (C16:C28) want to take it and put it into table1 in field NAMES .. how i can write it in query ?

note am using Microsoft SQL Server Management .. and try to get all my xls and import it into data base via sql query take from those files data and put it into my database ..

INSERT INTO [table1] (Names) VALUES ('&C16&') to ('&C28&')

is this true ? idk how to write it .. need help

Upvotes: 4

Views: 5391

Answers (1)

Conrad Frix
Conrad Frix

Reputation: 52645

When you use openrecordset you can specify a range [Sheet1$C16:C28] on the table in the query parameter

INSERT INTO [table1] (Names)
SELECT *
FROM OPENROWSET 
('Microsoft.Jet.OLEDB.4.0', 
  'Excel 8.0;Database=C:\Foo.xls;HDR=NO', 
   'select * from [Sheet1$C16:C28]') AS t

Upvotes: 2

Related Questions