Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. What's wrong with Query String;

What's wrong with Query String;

Scheduled Pinned Locked Moved Database
databasequestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bo Hunter
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • B 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

      A Offline
      A Offline
      Alexander Kojevnikov
      wrote on last edited by
      #2

      AND operator has a higher priority than OR. 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

      J 1 Reply Last reply
      0
      • A Alexander Kojevnikov

        AND operator has a higher priority than OR. 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

        J Offline
        J Offline
        Jon Hulatt
        wrote on last edited by
        #3

        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>

        B 1 Reply Last reply
        0
        • J Jon Hulatt

          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>

          B Offline
          B Offline
          Bo Hunter
          wrote on last edited by
          #4

          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

          A 1 Reply Last reply
          0
          • B 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

            A Offline
            A Offline
            Alexander Kojevnikov
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups