Link to home
Start Free TrialLog in
Avatar of Sandra Smith
Sandra SmithFlag for United States of America

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Avatar of Sandra Smith

ASKER

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
This worked, thank you.
Thanks for the grade.  Good luck with your code.  -Jim