Solved

Removing an apostrophe using update comand

Posted on 2008-10-15
4
446 Views
Last Modified: 2012-05-05
I have some data that needs to be updated. I need to update codes that have an apostrophe, removing the apostrophe. Only problem is, SQL uses Apostrophies so my script doesnt work.

Update "Patient" set "Primary Insured Gaurantor" = 'DALES0000' where "Primary Insured Gaurantor" = "D'ALES0000" <- used quotes here just so you could see exactly what I was trying to update. I am trying to remove the apostrophe from D'ALES0000. Several others to do in several tables.
0
Comment
Question by:wdabbs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 60

Expert Comment

by:chapmandew
ID: 22724323
update patient
set [primary insured grantor] = replace([primary insured grantor], '''', '')
0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 22724465
you need to use back-to-back apostrophes:
Update "Patient" set "Primary Insured Gaurantor" = 'DALES0000' where "Primary Insured Gaurantor" = 'D''ALES0000'
0
 

Expert Comment

by:obtek123
ID: 22726724
set quoted_identified will work, here is the example from BOL. Once you set the quoted Identifier the single quote will be treated as data.

Good luck

SET QUOTED_IDENTIFIER OFF
GO
-- An attempt to create a table with a reserved keyword as a name
-- should fail.
CREATE TABLE "select" ("identity" INT IDENTITY NOT NULL, "order" INT NOT NULL)
GO

SET QUOTED_IDENTIFIER ON
GO

-- Will succeed.
CREATE TABLE "select" ("identity" INT IDENTITY NOT NULL, "order" INT NOT NULL)
GO

SELECT "identity","order"
FROM "select"
ORDER BY "order"
GO

DROP TABLE "SELECT"
GO

SET QUOTED_IDENTIFIER OFF
GO
0
 

Author Comment

by:wdabbs
ID: 22734603
Worked perfectly! Thanks
0

Featured Post

MongoDB Through a MySQL Lens

This article looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how the fundamental information of how to create a table.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question