Menu

using LIKe % in SQL

Rob
2009-03-27
2013-04-29
  • Rob

    Rob - 2009-03-27

    Hi

    I am trying to pass this select statement using pymssql:

    SELECT Customer_Key , Name , TerritoryID FROM Customer WHERE (NOT (Customer_Key LIKE '[ZZ]%'))

    and keep getting this error:

    ValueError: unsupported format character ''' (0x27) at index 91

    How do I ues the % symbol in LIKE cluase for SQL statements? 

     
    • A

      A - 2009-03-27

      It is a bug in pymssql. Until 1.0.2 is released you must use %% instead of %

       
      • Rob

        Rob - 2009-03-27

        yes, I finally got there, the big problem I thought was python being unhappy with the ' right after the %  (as in this -> %' caused the problem)

        I tried the like 'abc&&' but that failed to.  My eventual solution was something like this:

        SQL = "SELECT blah FROM table WHERE name LIKE 'abc"
        SQL += "%%"
        SQL += "' ORDER BY blah"

         
        • A

          A - 2009-03-27

          This should work:

          SQL = "SELECT blah FROM table WHERE name LIKE 'abc%%' ORDER BY blah" 

          Sorry for the inconvenience, this bug slipped unnoticed.

           
          • Rob

            Rob - 2009-03-27

            There was no real inconvenience, and I learned a few things so that was good ;-)

            Thanks,

             

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.