include either OR or AND in SQL statement

  • Thread starter Thread starter Associates
  • Start date Start date
A

Associates

Hi,

I was trying to execute the following query in Access 03 but unable to
achieve a desired outcome.

mySQL = "SELECT ID, FirstName, LastName, Category, Subjects, EntryDate"
mySQL = mySQL & " FROM studentDB"
mySQL = mySQL & " WHERE (FirstName like '" & myFName & "' " & myLink &
"LastName like '" & myLName & "') And EntryDate between #10-Mar-2006# and
#20-Mar-2009#"

where myLink is a variable that has a value of either "OR" or "AND"
depending on a condition or criteria.

This return nothing at the moment which is wrong. I suspect myLink is the
cause. But how do i go about this. I wonder if anyone might be able to help
me out.

Any helps would be greatly appreciated.

Thank you in advance
 
Associates said:
Hi,

I was trying to execute the following query in Access 03 but unable to
achieve a desired outcome.

mySQL = "SELECT ID, FirstName, LastName, Category, Subjects, EntryDate"
mySQL = mySQL & " FROM studentDB"
mySQL = mySQL & " WHERE (FirstName like '" & myFName & "' " & myLink &
"LastName like '" & myLName & "') And EntryDate between #10-Mar-2006# and
#20-Mar-2009#"

where myLink is a variable that has a value of either "OR" or "AND"
depending on a condition or criteria.

This return nothing at the moment which is wrong. I suspect myLink is the
cause. But how do i go about this. I wonder if anyone might be able to
help
me out.

Any helps would be greatly appreciated.


You would need to fix at least one thing -- there's no space before
"LastName like". So try this:

mySQL = mySQL & _
" WHERE (FirstName like '" & myFName & "' " & myLink &
" LastName like '" & myLName & "') And EntryDate between " & _
"#10-Mar-2006# and #20-Mar-2009#"

If that change alone doesn't work, use Debug mode to examine the value of
mySQL after you finish building it, and see if the statement looks valid.
 
Hi,

I was trying to execute the following query in Access 03 but unable to
achieve a desired outcome.

mySQL = "SELECT ID, FirstName, LastName, Category, Subjects, EntryDate"
mySQL = mySQL & " FROM studentDB"
mySQL = mySQL & " WHERE (FirstName like '" & myFName & "' " & myLink &
"LastName like '" & myLName & "') And EntryDate between #10-Mar-2006# and
#20-Mar-2009#"

where myLink is a variable that has a value of either "OR" or "AND"
depending on a condition or criteria.

This return nothing at the moment which is wrong. I suspect myLink is the
cause. But how do i go about this. I wonder if anyone might be able to help
me out.

Any helps would be greatly appreciated.

Thank you in advance

Unless the string variables myFName and myLName contain wildcards, you're not
going to get any benefit from the LIKE operator. Without wildcards LIKE works
exactly the same as =. How are myFName and myLName getting specified?
 
Back
Top