0

Hoping there is a way to do this, I want to use open row set to select only specific columns from a file that has many more than what I need. I'm trying to do the below but getting an error on the FROM clause.

 `INSERT INTO TestData ([Column1],[Column2])
    FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel 12.0;Database=C:\test.xlsx;', 
    'SELECT [Column1],[Column2] FROM [Sheet1$]')`

Msg 156, Level 15, State 1, Line 50 Incorrect syntax near the keyword 'FROM'.

1 Answer 1

2

It should be this way:

INSERT INTO TestData (
[Column1],
[Column2])
SELECT
[Column1],
[Column2]
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel 12.0;Database=C:\test.xlsx;','SELECT * FROM [Sheet1$]') 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.