I am running a simple query using VB (This isnt a VB Question, dont worry!) on SQL Server Compact. I have the query below being created, and then added to if a flower location doesn't equal nothing (if it is nothing, its returning all the values) now, when this query runs and I select a flower location, i.e. L3 I want it to return all values where the flower location is equal to L3 and those where it is equal to L5.
Expand|Select|Wrap|Line Numbers
- statement = "SELECT * FROM tblDetails WHERE Dummy LIKE 'x'"
- If flowerLocation <> "" Then
- statement = statement + " AND Location_ID LIKE '" + flowerLocation + "'" OR Location_ID LIKE 'L5'"
- End If
Expand|Select|Wrap|Line Numbers
- If flowerFamily <> "" Then
- statement = statement + " AND Family_ID LIKE '" + flowerFamily + "'"
- End If
- If flowerHeight <> "" Then
- statement = statement + " AND Height LIKE '" + flowerHeight + "'"
- End If
so a possible statement could be :
Expand|Select|Wrap|Line Numbers
- SELECT * FROM tblDetails WHERE Dummy LIKE 'x'
- AND Location_ID LIKE 'L3' OR Location_ID LIKE 'L5'
- AND Family_ID LIKE 'F2'
Are there issues about using an OR then an AND statement? its like the AND statement isn't "filtering" out the results returned by the 1st bit of the query.
If I take out the bit of code adding the OR Location_ID LIKE 'L5' on the code works fine, and only returns those which meet all your criteria, but it's the OR thats causing trouble, but i want to return all the values that match the location selected and those with L5, but not other locations. (NB The user can not select L5)
This is code for a search function, so the SELECT * is returning all the values in the DB and the ANDs are filtering out the stuff I dont want if the user selects something.
Hope thats clear, pls PM me if I haven't explained it well enough,
Thanks very much!!!
Mark