Solved

Removing an apostrophe using update comand

Posted on 2008-10-15
4
405 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
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now