Results 1 to 6 of 6
  1. #1
    tmcrouse is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Apr 2009
    Posts
    169

    Trying to remove a ' from a string

    I am using Access 2010 and trying to do a replace to remove a ' from a string and it does not work. I am using:



    replace([myfield], "'", "")

    It runs the query but does not work as I still see:

    In the last 6 months, did you get information or
    help from your health plan’s customer service?

    I have several fields in this large database that have the ' and I need to remove them so it says plans or doctors instead of plan's or doctor's. Just as an example. I need to do this because this data is actually going into SQL and SQL uses ' ' to notate strings. So if I move this data into SQL I will see:

    In the last 6 months, did you get information or
    help from your health plan’s customer service? and where I see plan's it places plan in black and then ' in red and then s in black. I am not sure if anyone out there knows how SQL Server works but I have to remove ' from anything I have because of how SQL Server operates.

  2. #2
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Can you give us the SQL code ?
    I am convinced there is a way to get around this by making SQL understand that the bit with the Appostrophe is text and not code.

  3. #3
    tmcrouse is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Apr 2009
    Posts
    169
    update
    mytable
    set
    question ='In the last 12 months, did you have an illness, injury, or condition that needed care right away in a clinic, emergency room, or doctors office?'
    where
    question ='In the last 12 months, did you have an illness, injury, or condition that needed care right away in a clinic, emergency room, or doctor's office?'
    update my table
    set question = '
    In the last 12 months, did you look forany information in written materials oron the Internet about how your health plan works?'
    where question = '
    In the last 12 months, did you look forany information in written materials oron the Internet about how your health plan's works?

    There are other questions. I typed this directly in the SQL Server. I want to remove the ' from any of the sentences because of the fact that SQL treats ' as the way to say between this is a string. Like if I name Year as a nchar(10) and I say 'Year' my field will show just Year and treat it as text.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Here is an example of using an Escape Character in Transact SQL for a single quote.
    http://blog.sqlauthority.com/2008/02...racter-string/

  5. #5
    tmcrouse is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Apr 2009
    Posts
    169
    Quote Originally Posted by ItsMe View Post
    Here is an example of using an Escape Character in Transact SQL for a single quote.
    http://blog.sqlauthority.com/2008/02...racter-string/

    will try that thanks

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    In some of those examples, the apostrophe is correct grammar but you want to remove all regardless?

    Instead of removing the apostrophe, I force the SQL to accept it as text instead of processing it as special character (delimiter).

    Replace([myfield], "'", "''")

    Example from my db:

    CurrentDb.Execute "INSERT INTO VibReportData(LabNum, StateNum, ProjectName, Metric, Density0)" & _
    " VALUES('" & rs!LABNUM & "', '" & rs!StateNum & "', '" & Replace(rs!ProjectName, "'", "''") & "', " & rs!Metric & ", '" & RRound(dblDensC, IIf(rs!Metric = True, 0, 1)) & "')"

    However, seems your code to remove the character should also work so something else is going on. As requested, provide the attempted SQL statement for analysis if you need more help. Are you trying to run an Access UPDATE object to correct the text in table? How many records are involved? Is this a 1-time event? Maybe just use the intrinsic Find/Replace dialog? Do you want to remove the s as well?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 04-14-2015, 03:26 PM
  2. Replies: 5
    Last Post: 02-20-2014, 10:17 AM
  3. Replies: 5
    Last Post: 03-10-2011, 02:19 PM
  4. Remove zeros within a number string
    By catguy in forum Queries
    Replies: 3
    Last Post: 02-25-2010, 07:47 AM
  5. I need to remove a dash from a number string.
    By catguy in forum Programming
    Replies: 3
    Last Post: 02-18-2010, 02:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums