Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
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.

E.g.:

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.4k 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';

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...