How do I deal with an apostrophe in a string when referring to that string in an SQL statement?
11/10/2018

When using an apostrophe in SQL scripts we come across an issue as this is also used to denote the start and end of a string therefore the apostrophes are ignored and the string ends early and you either get undesired results or no results at all.

To get around this issue what we need to do is use an escapingout method.
To do this we simply add an extra apostrophe like this:

INSERT INTO Users (Name) VALUES (’Jamie’’O’Sands’)

This will insert Jamie’O’Sands into a database.

As you can see the additional apostrophes have been inserted and have returned what was expected.

By using keyintelligence.uk, you agree to our use of cookies to enhance your experience.