View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 10,593
Default SQL Select string

An xls list can be treated as just another table, and queried the same way.
For this, we need to have headers in row, and this is the column names for
the SQL query. You can query that table, using WHERE clauses against those
column names. You must specify each column to qualify (WHERE) with the value
to be retrieved. To go back to my original

szSQL = "SELECT * FROM [" & SourceSheet$ & "$" & SourceRange$ & "] " & _
"WHERE LastName = '" & myName & "' AND KeyCode = '" & myCode

We have column names (headings) of LastName and KeyCode, this must be exact
match. myName and myCode are the variables that you wish to restrict the
query to.


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Geoff" wrote in message
...
So the WHERE clause should read something like:

WHERE fieldname = Last Name, Keycode, First Name and the other specific
headers I am looking for.

Is this possible working with lists in .xls wbooks?

Geoff

"Geoff" wrote:

That would give me the contents of columns LastName and KeyCode with
filters
myName and myCode.

I am just reading the first row of multiple Excel wbooks. This is to
establish data patterns. Column names are random and specific names (if
they
are there) can be in any column order.

Wbook1 keycode Source Title
Wbook2 List code Honorific Forename Surname keycode etc etc

Geoff

"Bob Phillips" wrote:

szSQL = "SELECT * FROM [" & SourceSheet$ & "$" & SourceRange$ & "] " &
_
"WHERE LastName = '" & myName & "' AND KeyCode = '" &
myCode
& "';"


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Geoff" wrote in message
...
Hi
I use ADO to get the first row of data from multiple unopened wbooks.
This string gets the contents of every cell in row 1 given that
SourceSheet
= "Sheet1" and SourceRange = "A1:IV1"

szSQL = "SELECT * FROM [" & SourceSheet$ & "$" & SourceRange$ & "];"

Instead of all the row how can I write a string to result in specific
names
eg Last Name, Keycode, Company etc?

T.I.A.

Geoff