For example Select @status = N ' stopped '
So why does the string stopped in front of it add N? And we found that some places add n or not, and some places have to add N.
N here means Unicode, which is a double-byte character. For Western characters, it is enough to be stored in one byte, and two bytes is required for the oriental character. Unicode is intended to be uniform, canonical, convenient, and compatible, and the western characters are also stored in two bytes.
This means that adding N means that the string is stored in Unicode.
but sometimes the same as not add, what is the reason? This is caused by an automatic conversion.
Like what:
DECLARE @status nvarchar (20)
Select @status = N ' stopped '
Select @status = ' Stopped '
In fact, the result of the above two sentences assignment is the same, because the variable type is nvarchar (Unicode type).
Some places (for example: sp_executesql parameters) cannot be converted automatically, so we need to add N.
What does it mean to add N to a string in T-SQL