Results 1 to 3 of 3

Thread: Function to parse Double and/or Single Quotes

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    80
    I have an SQL statement in an app that I'm modifying in which the value for the WHERE condition can have a single or a double quote in it and though I haven't seen it yet, it's probably just a matter of time when that value will contain both a single AND double quote.

    I can't seem to come up with a function to handle both and return a valid value without getting syntax errors.

    Thanks in advance.

    -Jack

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Code:
    Public Function CleanString(sTheString As String) As String
        Dim sRetVal As String
        sRetVal = Replace(sTheString, "'", "''")
        sRetVal = Replace(sRetVal, """", "''")
    End Function
    This code replaces all single and double quotes with two single quotes witch works in SQL.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2000
    Posts
    80
    Thanks for the reply there Joacim,

    This would work fine if I were inserting records but because this is in a where clause, the value that I would be trying to retrieve wouldn't come up because there would be no data to match it.

    Here are 3 examples of sample WHERE criteria and how the data already sits in the database.

    Example 1:
    4" Master - 20 1/8 x 4 3/4 x 52 1/8

    Example 2:
    "DUMMY" SHELF BOX

    Example 3:
    12' CARDBOARD EASEL - 12 X 12 X 12



    -JackV

Posting Permissions

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



Click Here to Expand Forum to Full Width