Writing SQL

T

Tylendal

I would like to write a single SQL statement that would allow me to place
different table names as needed and specify specific fields from this table.

The issue I am stumbling over is there are 30+ fields that have names like
1A, 2B, 4C, etc.

Each time the SQL runs I wish to select a specific field but for some reason
I get syntax errors. I can assign the field to a variable but getting the
variable into the SQL seems to be the issue. The SQL works fine if I
identify the field as 1A, 2B etc. but using the variable I get the error.

Appreciate your assistance.

Tylendal
 
J

John Nurick

Hi Tylendal,

strField1 = "1A"
strField2 = "4C"
strTable = "MyTable"

strSQL = "SELECT [" & strField1 & "], [" & strField2 & "] " _
& "FROM " & strTable & ";"
 
T

Tylendal

Thanks John...

When I saw your answer I asked myself why had I not thought of the [].
Appreciate the help.

-Tylendal

John Nurick said:
Hi Tylendal,

strField1 = "1A"
strField2 = "4C"
strTable = "MyTable"

strSQL = "SELECT [" & strField1 & "], [" & strField2 & "] " _
& "FROM " & strTable & ";"



I would like to write a single SQL statement that would allow me to place
different table names as needed and specify specific fields from this table.

The issue I am stumbling over is there are 30+ fields that have names like
1A, 2B, 4C, etc.

Each time the SQL runs I wish to select a specific field but for some reason
I get syntax errors. I can assign the field to a variable but getting the
variable into the SQL seems to be the issue. The SQL works fine if I
identify the field as 1A, 2B etc. but using the variable I get the error.

Appreciate your assistance.

Tylendal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top