Keep the apostrophe intact in an INSERTstatement SQL T-SQL

I am inserting data via  script but how do I keep the apostrophe intact?  The "\" escape does not work.

INSERT INTO Track (TrackID, AlbumID, Title, TrackNumber, Duration) VALUES (24,12,'You Won\'t See Me',3,202);

Sandra
Sandra SmithRetiredAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Use two apostropes
INSERT INTO Track (TrackID, AlbumID, Title, TrackNumber, Duration) 
VALUES (24,12,'You Won''t See Me',3,202);

Open in new window

btw not sure what the purpose of the backslash is.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Also, the above usually means that if you're INSERTing using a SELECT that you'll need to use REPLACE to convert to double-quotes for the insert..
CREATE TABLE #t1 (name varchar(25))
CREATE TABLE #t2 (name varchar(25))

INSERT INTO #t1 (name) VALUES ('Charley O''Brien') 
INSERT INTO #t2 (name) SELECT REPLACE(name, '', '''') FROM #t1

SELECT * FROM #t1
SELECT * FROM #t2

Open in new window

0
Sandra SmithRetiredAuthor Commented:
Thanks Jim.  Actually, this is a MySQL script that I am trying to convert to T-SQL so it has a few unfamiliar things in it.  The backslash seems to be the escape character for MySQL.  Let me try your suggestions and get back.

Sandra
0
Sandra SmithRetiredAuthor Commented:
This worked, thank you.
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the grade.  Good luck with your code.  -Jim
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.