Solved

Removing an apostrophe using update comand

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to shrink a transaction log file down to a reasonable size.

808 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