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 StringwithSinglequotesMsg 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'''
--addind CHAR(39)
DECLARE @string1 NVARCHAR(500) = 'single quotes'+ CHAR(39)
SELECT @string1 StringwithSinglequotes
No comments:
Post a Comment