Ask a Question related to Macromedia ColdFusion, Design and Development.

  1. #1

    Default SQL like statement

    Where am I doing wrong here?

    select company, womens from tblwshow where company LIKE '%things%'

    I know that there is a text "things" in some of the company names but it is
    not giving any output. I have used this code b4 too but I dont know where I m
    doing wrong this time.

    Thank you

    DDhillon Guest

  2. Similar Questions and Discussions

    1. If Statement???
      guys i was wondering if anybody here could help me. I have a page done up with all dynamic text and attributes on it that come from a management...
    2. Use of FOR statement
      I am reading through a book on Objects and References and I don't understand this statement: $sum += $_ for split //; I thought a FOR...
    3. AW: if-else-statement
      --On Wednesday, September 03, 2003 11:56 PM +0200 "B. Fongo" <mygrps@fongo.de> wrote: Look at the docs for CGI.pm under pragmas, the -nosticky...
    4. if statement
      I'm trying to write an if statement i have two field, Status and Attendance. "status" value can be active or inactive "Attendance" value is active...
    5. IIF statement
      Assuming the data is being entered via a form, then use the AfterUpdate event of the control that is bound to the signature field. The code you need...
  3. #2

    Default Re: SQL like statement

    Can you do a select * and see if you get ANY records? Step by step troubleshooting. What do you mean by it's not giving any output? What does the query's RECORDCOUNT return?
    Aegis Kleais Guest

  4. #3

    Default Re: SQL like statement

    Yes I have tried doing Select *. It is not showing any recordcount.
    DDhillon Guest

  5. #4

    Default Re: SQL like statement

    Could you possibly be dealing with a case sensitivity issue? Perhaps you can
    use a (database dependent) function to guarantee that you are matching case,
    such as....

    WHERE LOWER(company) LIKE '%things%'
    --or--
    WHERE LCASE(company) LIKE '%things%'
    ..etc.

    Phil

    paross1 Guest

  6. #5

    Default Re: SQL like statement

    Let me elaborate my problem little more. Actually I m trying to fing the
    specific word from the list of 50,000 companies. Lets say I want to find the
    company that name contains "things". I m trying to use this statement Select *
    from tblwshow where company like '%things%'. Do you think I m doing it right?

    I hope this will explain more.

    DDhillon Guest

  7. #6

    Default Re: SQL like statement

    You are doing it right. But as paross1 said is the DB case sensitive. What DB
    are you using? What is the datatype of the company field?
    Did you try paross1's solution?

    Also make sure that there are some companies that has the string you are using
    in the like constraint.

    basky Guest

  8. #7

    Default Re: SQL like statement

    For this kind of text search, verity is a much better tool and a much FASTER tool than a SQL like statement.... You can index the entire DB and search through it in miliseconds....
    BenDC Guest

  9. #8

    Default Re: SQL like statement

    I m using MS Access. The field is memo type. I m copying and pasting the string
    in statememnt. I have also tried using MS Access query view to see results. I
    dont see anything when I run it.

    SELECT * from tblwshow where company like '%AIRTIGER%'

    The company name is "ATE AIRTIGER EXPRESS CANADA INC"

    I think the query above should show some result.

    DDhillon Guest

  10. #9

    Default Re: SQL like statement

    I don't think you can use like operation on memo field in access. I am pretty sure about it, but please double check it.

    basky Guest

  11. #10

    Default Re: SQL like statement

    May be you can use Verity to solve this issue, or change the field type to varchar or equivalent thing in access.
    basky Guest

  12. #11

    Default Re: SQL like statement

    To make myself more clear. Let me put down the code here. I think it will help
    in understand the problem better:

    I m running a list loop that searches each item from the loop in the name of
    companies. Once it finds that item, it updates another field by putting 1 in it.

    <cfset
    thetext='Health,fitness,medical,physical,mental,sp iritual,spa,rejuvenation,relat
    ionship,knowledge,empowerment,dr,chiropractic,chir opractor,skin,massage,therapy,
    therapeutic,women,woman,feel,good,fit,curve,body,p leasure,her,she,physio,psychol
    ogy,psychological,book,bond,chapter,slim,acupunctu re,acupressure,tai,herb,herbal
    ,adult,power,sex,make,making,treatment,lather,bath ,dental,dentist,disorder,teach
    ing,teach,eye,female,age,lady,ladies,aerobic,optic al,optician,publish,weight,ref
    lex,reduce,control,sport,yoga'>


    <CFLOOP From = "1" To = "#listLen(thetext)#" INDEX = "i">
    <cfquery name="getdata" datasource="#mydsn.dsn#">
    select id,company,womens from tblwshow where company like
    '#listgetat(thetext,i)#'
    </cfquery>
    <cfoutput>
    #listgetat(thetext,i)#
    </cfoutput>

    </cfloop>
    <cfoutput query="getdata" maxrows="1000">
    <cfquery name="updatedata" datasource="#mydsn.dsn#">
    update tblwshow set womens='1' where id=#getdata.id#
    </cfquery>
    </cfoutput>
    </cfloop>

    DDhillon Guest

  13. #12

    Default Re: SQL like statement

    You can't use a like statement on a memo field in ms access. I think you can't even use a memo field in the where clause


    Ken
    The ScareCrow Guest

  14. #13

    Default Re: SQL like statement

    I have used like clause before in the memo foeld. Do you think I wrote the right code though?
    DDhillon Guest

  15. #14

    Default Re: SQL like statement

    Ok I think I found the problem.

    Use * instead of % signs. That let me use like on memo fields also. I tried
    this from the access and could get that to work. Try it from a cfm page and let
    us see how ODBC driver handles it.

    So your query should look like

    <cfquery name="getdata" datasource="#mydsn.dsn#">
    select id,company,womens from tblwshow where company like
    '*#listgetat(thetext,i)#*'
    </cfquery>


    Let us know if this has worked for you.



    basky Guest

  16. #15

    Default Re: SQL like statement

    I stand corrected, I was sure I read it somewhere, anyway

    basky, in access itself you use "*" when using a odbc driver you use "%"

    But I think I found the problem, reserved words

    Also there is no need to use the listgetat function

    <cfloop index="idx" list="#thetext#">
    <cfquery name="getdata" datasource="#mydsn.dsn#">
    select [id],[company],[womens] from tblwshow where [company] like '#idx#'
    </cfquery>
    <cfoutput>
    #idx#
    </cfoutput>

    Give that a try

    Ken

    The ScareCrow Guest

  17. #16

    Default Re: SQL like statement

    Thank you for all your guys help but this time I dont know maybe its newer
    version of CF things arent working for me. I tried putting '*' as a wild
    character in the query while using query view in access. It works fine. When I
    use the simple query written below in cf its not showing any result at all. It
    looks very simple but I dont know why its not working.

    <cfquery name="getdata" datasource="#apnadirectory.dsn#">
    select id,company,womens from tblwshow where company like '*SPA*'
    </cfquery>
    <cfoutput query="getdata">
    #company#<br><br>
    </cfoutput>

    DDhillon Guest

  18. #17

    Default Re: SQL like statement

    Did you try ScareCrow's suggestion. try using [ ] with % (if it does not work try * also)
    basky Guest

  19. #18

    Default Re: SQL like statement

    If it works in access, create your query in access, test, then copy the query and paste into your cfquery tag, then see if this works. Note you will have to change the "*" for "%"

    Ken
    The ScareCrow Guest

  20. #19

    Default Re: SQL like statement

    Try '%#things#%'


    Quote Originally Posted by DDhillon View Post
    Where am I doing wrong here?

    select company, womens from tblwshow where company LIKE '%things%'

    I know that there is a text "things" in some of the company names but it is
    not giving any output. I have used this code b4 too but I dont know where I m
    doing wrong this time.

    Thank you
    Unregistered Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139