Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Problems

Status
Not open for further replies.

Geee

Programmer
Apr 23, 2001
253
GB
I posted this in the SQL forum, but I hope someone on here can help as the response on this forum is so good!

I have the following statement that apparently is incorrect...

SELECT * FROM dbo.products WHERE (CategoryID LIKE '%') AND (ProductName LIKE '%%') AND ((CategoryID <> '') OR (CategoryID = '1 ')) ORDER BY ProductName

Basically I want to select all from the products table, where CategoryID contains % and ProdunctName contains %. IN addition to this the CategoryID should be not equal to nothing, or should be 1. I thought the brackets in the above statement would convey this. ANyone actually understand what I'm on about???

G -GTM Solutions, Home of USITE-
-=
 
Hi,

Have you tried this without the OR? Theoretically, you don't need it because Category=1 is one of the conditions covered by CategoryID <> ''. I'd write it as:

SELECT * FROM dbo.products WHERE (CategoryID LIKE '%') AND (ProductName LIKE '%%') AND (CategoryID <> '') ORDER BY ProductName;

Simon
 
% is a wildcard. so I bet your either returning nothing or everything. at any rate, you need to find out if there is an escape character for the % symbol. I honestly don't know if there is or isn't, it might change depending on your dbms. i think that might be your problem, though... hth
leo

------------
Leo Mendoza
lmendoza@students.depaul.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top