PDA

View Full Version : Solved: SQL Strings



Mavver
06-20-2007, 08:04 AM
Hello All

If I have two SQL statements like the following


strSQL = "SELECT * FROM tblSchool_Clean " & _
"WHERE tblSchool_Clean.PoE_Desc IN(" & strCriteria1 & ");"



strSQL = "SELECT * FROM tblSchool_Clean " & _
"WHERE tblSchool_Clean.ToE_Desc IN(" & strCriteria2 & ");"


is it possible to merge them into one by using an AND somewhere, I dont know how to do this so if it is possible can someone show me with the above example please.

Many Thanks

Mav

matthewspatrick
06-20-2007, 10:06 AM
Depends on what you mean by "merging" them. If you mean, 'give me a
result set that matches both criteria':


strSQL = SELECT * FROM tblSchool_Clean " & _
"WHERE PoE_Desc IN (" & strCriteria1 & ") " & _
"AND WHERE ToE_Desc IN (" & strCriteria2 & ")"


If you mean, 'give me a result set that matches at least one criterion':


strSQL = SELECT * FROM tblSchool_Clean " & _
"WHERE PoE_Desc IN (" & strCriteria1 & ") " & _
"OR WHERE ToE_Desc IN (" & strCriteria2 & ")"

Mavver
06-22-2007, 01:32 AM
many many thanks, and if I had Pivot Table to share I would give it you.

Mavver
06-22-2007, 06:28 AM
Alas it did not work, I placed the following string in the code and an error message box pops up with "Characters found after end of SQL statement


strSQL1 = "SELECT * FROM tblSchool_Clean " & _
"WHERE tblSchool_Clean.PoE_Desc IN(" & strCriteria1 & ");" & _
"AND WHERE tblSchool_Clean.ToE_Desc IN(" & strCriteria2 & );"


The code which follows this bit is


' Apply the new SQL statement to the query
qdf.SQL = strSQL1

' Empty the memory
Set db = Nothing
Set qdf = Nothing


Can anyone shed some light on this please, thanks ever so much in advance

Mav

matthewspatrick
06-22-2007, 06:41 AM
Mav,

You did not quite follow directions :)


strSQL1 = "SELECT * FROM tblSchool_Clean " & _
"WHERE tblSchool_Clean.PoE_Desc IN(" & strCriteria1 & ") " & _
"AND WHERE tblSchool_Clean.ToE_Desc IN(" & strCriteria2 & ");"

Mavver
06-22-2007, 07:07 AM
Another error message pops up this time (I cut and pasted this time)

Syntax error (missing operator) in query expression 'tblSchool_Clean.PoE_Desc IN ('School Phase One','School Phase Two') AND WHERE tblSchool_Clean.ToE_Desc IN ('School Type One','School Type Two')'.

....School Phase One/Two and School Type One/Two are the selection types.....

ta

Mav

geekgirlau
06-26-2007, 11:13 PM
strSQL1 = "SELECT * FROM tblSchool_Clean " & _
"WHERE tblSchool_Clean.PoE_Desc IN(" & strCriteria1 & ") " & _
"AND tblSchool_Clean.ToE_Desc IN(" & strCriteria2 & ");"

Mavver
06-28-2007, 01:50 AM
Geekgirl to the rescue

many thanks

Mav