SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    double quotation mark makes an error

    (1) 'Homerun!' he yelled.
    (2) "Homerun!" he yelled.
    I have the data above in myTable.
    And I have key "homerun!"

    Let's see the following code and its result.

    Code:
    code1 
    where say like "%#key#' %" 
    
    result1 
    (1) 'Homerun!' he yelled. 
    
    code2 
    where say like "%#key#" %" 
    
    result2 
    (2) "Homerun!" he yelled.

    I like to produce record(1) and record(2) at a same time.

    So I made the following code3, and it work fine when the key is "homerun!" or other words.
    Code:
    code3
    where (say like "%#key#' %") 
            or 
          (say like '%#key#" %')
    result3
    (1) 'Homerun!' he yelled. 
    (2) "Homerun!" he yelled.
    But above code seems make an SQL error when the key word is double quotation mark(").

    Do you see why it makes an errors when the key is double quotation mark(")?

    (Strangely, the key word the single quotation mark(') doesn't make an error. )

    Thanks in Advance
    Last edited by dotJoon; Nov 18, 2004 at 03:11.

  2. #2
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    As any of you don't reply, I think my question was something wrong.

    Okay,
    I'll make the point clearer
    Please forget about my question above.
    The following is the main point of my question.


    ...
    (7) 'Homerun!' he yelled.
    (8) He is running fast.
    ...
    I have the data above in myTable.

    I like to retrieve the record(7) but not to retrieve the record (8) with a key word "run".

    So I made the following code, and it works fine for that purpose.

    Code:
      select ID, say 
      from myTable
      where (say like "%#form.keyword#!' %")
    But problem with the above code is that it causes a coldfusion error, i.e."Syntax error or access violation:" when the keyword is double quotation mark(").

    Do you see what is the problem?

    How can I retrieve record (7) only
    with the keyword "run"
    without any Syntax error when the keyword is double quotation mark(")?

    Thanks in Advance

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    in sql, always use single quotes to delimit strings

    then, if the single quote occurs within a string, code two of them in a row
    Code:
    where say like '%#form.keyword#!'' %'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937
    in sql, always use single quotes to delimit strings

    then, if the single quote occurs within a string, code two of them in a row
    Code:
    where say like '%#form.keyword#!'' %'
    That's it. Thank you


Bookmarks

Posting Permissions

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