What's wrong with Query String;
-
SELECT [ID], Title, NodeType, ParentID, [Language], Description FROM SourceCode WHERE Title LIKE '%Title%' OR Code LIKE '%Title%' AND Language = 1 OR Language = 2 OR Language = 3 OR Language = 4 OR Language = 5 AND NodeType = 1 OR NodeType = 2 OR NodeType = 3 OR NodeType = 4 OR NodeType = 5 OR NodeType = 6 AND ParentID = 4 OR ParentID = 6 Do the numbers have to be quoted? Any Suggestions? Thank You Bo Hunter
-
SELECT [ID], Title, NodeType, ParentID, [Language], Description FROM SourceCode WHERE Title LIKE '%Title%' OR Code LIKE '%Title%' AND Language = 1 OR Language = 2 OR Language = 3 OR Language = 4 OR Language = 5 AND NodeType = 1 OR NodeType = 2 OR NodeType = 3 OR NodeType = 4 OR NodeType = 5 OR NodeType = 6 AND ParentID = 4 OR ParentID = 6 Do the numbers have to be quoted? Any Suggestions? Thank You Bo Hunter
AND
operator has a higher priority thanOR
. You might want to use parentheses:SELECT [ID], Title, NodeType, ParentID, [Language], Description
FROM SourceCode
WHERE (Title LIKE '%Title%' OR Code LIKE '%Title%')
AND (Language = 1 OR Language = 2 OR Language = 3 OR Language = 4 OR Language = 5)
AND (NodeType = 1 OR NodeType = 2 OR NodeType = 3 OR NodeType = 4
OR NodeType = 5 OR NodeType = 6)
AND (ParentID = 4 OR ParentID = 6)HTH, Alexandre Kojevnikov MCAD charter member Leuven, Belgium
-
AND
operator has a higher priority thanOR
. You might want to use parentheses:SELECT [ID], Title, NodeType, ParentID, [Language], Description
FROM SourceCode
WHERE (Title LIKE '%Title%' OR Code LIKE '%Title%')
AND (Language = 1 OR Language = 2 OR Language = 3 OR Language = 4 OR Language = 5)
AND (NodeType = 1 OR NodeType = 2 OR NodeType = 3 OR NodeType = 4
OR NodeType = 5 OR NodeType = 6)
AND (ParentID = 4 OR ParentID = 6)HTH, Alexandre Kojevnikov MCAD charter member Leuven, Belgium
Furthermore, you really ought to use "IN":-
SELECT [ID], Title, NodeType, ParentID, [Language], Description
FROM SourceCode (nolock)
WHERE (Title LIKE '%Title%' OR Code LIKE '%Title%')
AND Language IN (1,2,3,4,5)
AND NodeType IN (1,2,3,4,5,6)
AND ParentID IN (4,6)#include <beer.h>
-
Furthermore, you really ought to use "IN":-
SELECT [ID], Title, NodeType, ParentID, [Language], Description
FROM SourceCode (nolock)
WHERE (Title LIKE '%Title%' OR Code LIKE '%Title%')
AND Language IN (1,2,3,4,5)
AND NodeType IN (1,2,3,4,5,6)
AND ParentID IN (4,6)#include <beer.h>
Will the IN operator work in Access? I forgot to mention that. And also some of the idetifiers like Language has to be exscaped. Does that also have to be exscaped in OleDbParameter like so, OleDbParameter param = new OleDbParameter( "[Language]", bla bla ); Is this correct? Thank You Bo Hunter
-
Will the IN operator work in Access? I forgot to mention that. And also some of the idetifiers like Language has to be exscaped. Does that also have to be exscaped in OleDbParameter like so, OleDbParameter param = new OleDbParameter( "[Language]", bla bla ); Is this correct? Thank You Bo Hunter
Bo Hunter wrote: Will the IN operator work in Access? Yep, it will. Bo Hunter wrote: Does that also have to be exscaped in OleDbParameter Probably it has to be escaped. This won't hurt anyway ;) Alexandre Kojevnikov MCAD charter member Leuven, Belgium