What does it mean to add N to a string in T-SQL

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.