SQL Server – Using a String with Single Quotes in a Table

sql servert-sql

I'm trying to insert the following string, as written, into a table:

'affinity mask', 0

However I can't figure out how exactly I need to escape the quotes. It always wants to treat the , 0 as a separate column.

How can I escape the comma properly?

Best Answer

You need to double-up apostrophes to embed them within a string, since they also serve as string delimiters:

INSERT dbo.table(column) VALUES('''affinity mask'',0');