Query (Full Version)

All Forums >> [Web Development] >> ASP and Database



Message


Guest -> Query (3/8/2001 20:55:00)

Here is a SQL query i am running in the DRW

SELECT * FROM table
WHERE (lname = '::lname::' or ID = '::id::')

This query works fine however it doesnt give me desired results. What i am looking to do is to be able to enter the LName and receive results, or enter both LName and ID and get filtered results where only the criteria entered in both fields is returned. Currently if i enter Smith in LNAME and 227 in ID i get returned everyone named smith and everyone with ID 227. I want just the SMITHS with ID 227. Or If I just put in 227 in ID and leave LNAME field blank I just want ID 227 returned. Basically i want to add more fields to search on and just have values returned matching the criteria I enterd into the filed (Note: some search fileds may be left blank and Id like to search on the remaining search fields) Thanks





Elecia -> RE: Query (3/8/2001 23:25:00)

I'm sure that there are other solutions to your problem and this may not be the best one but it will do what you want.

You could set the default value of each of your text boxes to * or % if forget now which one works as a wild card in FrontPage. Use validation on the text boxes so that they always a have some value (or a wild card). Then you can add as many fields as you like using and in SQL statement.

SELECT * FROM table
WHERE (lname = '::lname::' and ID = '::id::'and state = '::state::' )

So if the user entered only a last name of smiths and wild cards for the other 2 fields they would get all the smiths. If they entered a last name of smith and the state of Florida they would get all smiths in florida and so on.

EE





Vince from Spain -> RE: Query (3/9/2001 20:12:00)

Here's another idea . . . .

SELECT * FROM table
WHERE (lname = '::lname::' OR '::lname::'='') AND (ID = '::id::' OR '::id::'='')

So if a field is blank it matches the '::field::'='' part of the statment, which would yield TRUE . . . well, I'm sure you get it anyway ;)

You can just extend it by adding for instance . . .

SELECT * FROM table
WHERE (lname = '::lname::' OR '::lname::'='') AND (ID = '::id::' OR '::id::'='') AND (otherfield='::otherinput::' OR '::otherinput::'='')

All the best

Vince

------------------
Internet Business Solutions S.L.(Spain)





Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.046875