like statment

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Fary4u
    Contributor
    • Jul 2007
    • 273

    #1

    like statment

    Hi

    i'm trying to search the value in my following field. i don't know why it's giving me this error

    Code:
    select * FROM products WHERE (products.CatalogID='" & strCatalogID & "') AND (products.productDescc like '%"&styno&"%'") ")
    without wildcard it's works fine but wd wildcard gives error
    Unterminated string constant. ?
    Last edited by Atli; Jun 7 '09, 01:10 PM. Reason: Moved from the insights forum into the answers forum.
  • Fary4u
    Contributor
    • Jul 2007
    • 273

    #2
    yes sorted but executed query but no result found ?

    Code:
    select * FROM products WHERE (products.CatalogID='" & strCatalogID & "') AND (products.productDescc like '%" & styno & "%') ")
    still can't find the styno value

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hi.

      Can you show us what the query looks like after you construct it?

      Meaning:
      [code=vb]
      Dim colValue As String = "someValue"
      Dim sql As String = "SELECT * FROM myTbl WHERE col = '" & colValue & "'"

      Response.Write( sql) ' What would this show you?
      [/code]

      Comment

      • Fary4u
        Contributor
        • Jul 2007
        • 273

        #4
        Hi thanks for ur reply

        the problem is not in query anymore it's bring the result but it's not searching value in the variable but variable values passing parameters ? ? ? ?

        i'm very much confused wht's going on ? ? ?

        my DB Values like this

        Code:
        CatalogID  |  productDess
        1  |  x / y / z
        2  |  A / B / C
        3  |  1 / 2 / 3
        result should b like this
        Code:
        (CatalogID='2') AND (productDescc like '%B%')
        coding
        Code:
        select * FROM products WHERE (products.CatalogID='" & strCatalogID & "') AND (products.productDescc like '%" & styno & "%') ")
        it's working fine & donig the same i would like to do but not returning value from " B " result

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          That query, executed against that data (overlooking the column name typo) should only return the second row

          Originally posted by Fary4u
          the problem is not in query anymore it's bring the result but it's not searching value in the variable but variable values passing parameters ? ? ? ?
          I'm afraid I don't understand what you are saying here.
          Could you try to explain this a little better?

          Aside from that, there are a couple of things that you might want to look into.
          1. Numeric values in queries should not be quoted, like your CatalogID.
            It should be [code=mysql](CatalogID=2)[/code]
            (Assuming CatalogID is an integer)

          2. Your productDescc column is storing multiple values.
            This violates the most basic rule of relational database design.
            Each field should only contain a single value, and never a list of values.
            See this article on Database Normalization and Table Structures to learn more.

          Comment

          Working...