Question about SQL Syntax

C

CJ

Hi!

Regarding this statement:

sSQL = "SELECT * FROM Table WHERE fkField = 1"

fkField is a lookup field that contains 3 values:
Value1, Value2 & Value3

What is the proper syntax so that I am always checking
against Value2?

Thanks in advance for your help!
 
M

MDW

Not sure what you mean by that. fkField can only have one of three values? If that's the case, then hardcode that value into your SQL statement. So if Value2 is 2, then your statement would look like this

sSQL = "SELECT * FROM Table WHERE fkField = 2

----- CJ wrote: ----

Hi

Regarding this statement

sSQL = "SELECT * FROM Table WHERE fkField = 1

fkField is a lookup field that contains 3 values
Value1, Value2 & Value

What is the proper syntax so that I am always checking
against Value2

Thanks in advance for your help
 
J

John Vinson

Hi!

Regarding this statement:

sSQL = "SELECT * FROM Table WHERE fkField = 1"

fkField is a lookup field that contains 3 values:
Value1, Value2 & Value3

No, it doesn't contain Value1, Value2 OR Value3. It *APPEARS* to,
because of Microsoft's misleading, misdesigned, and obnoxious Lookup
misfeature, which conceals the actual content of your table - an
arbitrary numeric value - behind the looked-up field. A SQL statement
will always look in the actual table; it knows nothing about any
"lookups".
What is the proper syntax so that I am always checking
against Value2?

Create a Query joining the main table to the lookup table:

sSQL = "SELECT Table.* FROM Table INNER JOIN Lookuptable" _
& " ON Table.fkField = Lookuptable.pkField"_
& " WHERE Lookuptable.Textfield = 'Value2'"
 

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