SQL Server - [T-SQL Handling single quotes within a string]

Two ways to handle single quotes within a string to avoid below error:

Msg 105, Level 15, State 1, Line 1
Unclosed quotation mark after the character string 'single quotes'

EXAMPLE :

--adding 2 single quotes if you need 1 single quotes in the resultset



DECLARE @string NVARCHAR(500) = 'single quotes'''
SELECT @string StringwithSinglequotes


--addind CHAR(39)

DECLARE @string1 NVARCHAR(500) = 'single quotes'+ CHAR(39)
SELECT @string1 StringwithSinglequotes









No comments: