Page 1 of 1

A search question

Posted: Sun Jan 27, 2008 1:57 pm
by micknc
I have written a search query with good results but now I need to add a new parameter to it and I am getting no where. I am brand new so this is probably something very easy I am overlooking.

Here is what I have:
SELECT * FROM SOHEAD WHERE upper($field)='$find' AND STATUS='P' ORDER BY SO_NO DESC

That is working great.

Now I need to add another variable to the status. I need to return all entries that =$find and that have a status of p or v. I have tired about every combination but I am stuck:

This returns only staus=p
SELECT * FROM SOHEAD WHERE upper($field)='$find' AND STATUS='P' OR 'V' ORDER BY SO_NO DESC

This returns an error:
SELECT * FROM SOHEAD WHERE upper($field)='$find' AND STATUS='P' OR upper($field)='$find' AND STATUS= 'V' ORDER BY SO_NO DESC

This returns correctly on status=p but returns all status=v
SELECT * FROM SOHEAD WHERE upper($field)='$find' AND STATUS='P' OR STATUS='V' ORDER BY SO_NO DESC

Is there something easy I am missing?
Thanks

Re: A search question

Posted: Sun Jan 27, 2008 2:08 pm
by JAM
Perhaps try different approaches;

Code: Select all

SELECT * FROM SOHEAD WHERE UPPER($field)='$find' AND STATUS IN('P','V') ORDER BY SO_NO DESCSELECT * FROM SOHEAD WHERE UPPER($field)='$find' AND (STATUS='P' OR STATUS='V') ORDER BY SO_NO DESC

Re: A search question

Posted: Sun Jan 27, 2008 5:33 pm
by micknc
Yes, I tried the first one and it worked perfectly.

Thanks. I am learning slowly but surely.

Re: A search question

Posted: Mon Jan 28, 2008 4:40 pm
by califdon
micknc wrote:Yes, I tried the first one and it worked perfectly.

Thanks. I am learning slowly but surely.
That's the only way! :teach: