PDA

View Full Version : SQL 'OR' Function?


greentra
04-20-2006, 08:14 AM
I have a form with a dropdown box which pulls records from an Access database subject to: WHERE dbfield = dropdownlist item selected. This all works fine, but now I want to add an 'All' field to my dropdownlist but I cannot see a way to fit this into the structure since the sql filters results for WHERE field=dropdown item. I have tried variations using LIKE and % in the sql but it doesn't seem to work. I am using dreamweaver 8.
I'm sure there is a simple solution . . . any advice please?

davidj
04-20-2006, 09:27 AM
if this was PHP i would be able to help but my asp skills are lacking

try dynamicaly creating your WHERE clause depending on what has been selected

when you catch the search values and they ARE NOT NULL then start building your query

pseudocode

if (fieldvalue is not null){$var1 = 'db_fileld = '.fieldvalue}
if (fieldvalue2 is not null){$var2 = 'db_fileld = '.fieldvalue2}

etc

then all you have to do is concat your query together

select * from table where [your code var here]
example...


select * from table where $var1 and $var2

greentra
04-20-2006, 09:37 AM
Thanks. Will give that a try. Was hoping there was some sort of wildcard type function I could use instead as I am not so hot on syntax in ASP/SQL when inserting dynamic code. Will have to play around with it I guess . . .

davidj
04-20-2006, 10:58 AM
you can use % as a wild card but this would be written as...

LIKE '%'

so you would have to check that your ALL value has been selected and then dynamicaly change your operator from = to LIKE