Question

I have been searching for a solution for a while, and I find myself coming up empty handed.

The question is: Can you build a SQL query against a worksheet if you don't have a distinct header row for column references?

Easily enough:

  |     A     |     B
1 | FirstName | LastName
2 | John      | Davis
3 | Mary      | Parker

SELECT [LastName] FROM [Sheet1$] WHERE [FirstName] = 'John'

--> "Davis"

However, I tend to work with header-less CSV files, so what could I do if I don't have the header row to steer by?

  |     A     |     B
1 | John      | Davis
2 | Mary      | Parker
SELECT ??? FROM [Sheet1$] WHERE ??? = 'John'

To extend the question, it could equally interesting to know how to reference a row number - if possible - say I want to find the Last Name (column B) relative to row [2]

Thanks in advance for any input on my conundrum!

-B

Was it helpful?

Solution

You can go through this link:

http://www.sql-server-helper.com/tips/read-import-excel-file-p02.aspx

Providing the HDR attribute as NO, will automatically name the columns as F1 to Fn.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top