Question about SQL Syntax

  • Thread starter Thread starter CJ
  • Start date Start date
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!
 
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
 
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'"
 
Back
Top