Explore Courses Blog Tutorials Interview Questions
0 votes
in SQL by (20.3k points)

I want something like

DECLARE myVariable nvarchar[MAX] = "hello world".

Bonus points if you show me how to encode a quote in the string.


I want the string to read

John said to Emily "Hey there Emily"

my attempt would be

DECLARE myVariable nvarchar[MAX] = "John said to Emily \"Hey there Emily\""

1 Answer

0 votes
by (40.7k points)

Try using the below code: 

DECLARE @var nvarchar(max) = 'Man''s best friend';

Note: Since the string delimiter is ' and not ", there is no need to escape ":

You can change the ' is escaped by doubling it to '' like this:

DECLARE @var nvarchar(max) = '"My Name is Luca" is a great song';

Browse Categories