Connecting Tech Pros Worldwide Forums | Help | Site Map

like statment

Familiar Sight
 
Join Date: Jul 2007
Location: United Kingdom
Posts: 203
#1: Jun 7 '09
Hi

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

Expand|Select|Wrap|Line Numbers
  1. select * FROM products WHERE (products.CatalogID='" & strCatalogID & "') AND (products.productDescc like '%"&styno&"%'") ")
  2.  
without wildcard it's works fine but wd wildcard gives error
Unterminated string constant. ?

Familiar Sight
 
Join Date: Jul 2007
Location: United Kingdom
Posts: 203
#2: Jun 7 '09

re: like statment


yes sorted but executed query but no result found ?

Expand|Select|Wrap|Line Numbers
  1. select * FROM products WHERE (products.CatalogID='" & strCatalogID & "') AND (products.productDescc like '%" & styno & "%') ")
  2.  
still can't find the styno value
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,751
#3: Jun 7 '09

re: like statment


Hi.

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

Meaning:
Expand|Select|Wrap|Line Numbers
  1. Dim colValue As String = "someValue"
  2. Dim sql As String = "SELECT * FROM myTbl WHERE col = '" & colValue & "'"
  3.  
  4. Response.Write(sql) ' What would this show you?
  5.  
Familiar Sight
 
Join Date: Jul 2007
Location: United Kingdom
Posts: 203
#4: Jun 7 '09

re: like statment


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

Expand|Select|Wrap|Line Numbers
  1. CatalogID  |  productDess
  2. 1  |  x / y / z
  3. 2  |  A / B / C
  4. 3  |  1 / 2 / 3
  5.  
result should b like this
Expand|Select|Wrap|Line Numbers
  1. (CatalogID='2') AND (productDescc like '%B%') 
  2.  
coding
Expand|Select|Wrap|Line Numbers
  1. select * FROM products WHERE (products.CatalogID='" & strCatalogID & "') AND (products.productDescc like '%" & styno & "%') ")
  2.  
it's working fine & donig the same i would like to do but not returning value from " B " result
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,751
#5: Jun 7 '09

re: like statment


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

Quote:

Originally Posted by Fary4u View Post

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
    Expand|Select|Wrap|Line Numbers
    1. (CatalogID=2)
    (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.
Reply