Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server 2005: what does the letter N for (...WHERE Name LIKE N'F%')

Just like the subject stated:

what does the letter N do in SQL like this:

SELECT P.ProductID,
       S.SupplierID,
       S.CompanyName
FROM Suppliers AS S JOIN Products AS P
     ON (S.SupplierID = P.SupplierID)
WHERE P.UnitPrice > $10
  AND S.CompanyName LIKE N'F%' -- what is the N for?
like image 733
kacalapy Avatar asked Mar 10 '11 17:03

kacalapy


People also ask

What does N in SQL Server mean?

The "N" prefix stands for National Language in the SQL-92 standard, and is used for representing Unicode characters. In the current standard, it must be an upper case , which is what you will typically find implemented in mainstream products.

What does N in front of a SQL string mean?

You may have seen Transact-SQL code that passes strings around using an N prefix. This denotes that the subsequent string is in Unicode (the N actually stands for National language character set). Which means that you are passing an NCHAR, NVARCHAR or NTEXT value, as opposed to CHAR, VARCHAR or TEXT.

What is n Select in SQL?

n or N refers to Unicode... It means that the text in the variable uses Unicode. It also means that the size of the variable is 2 bytes per character instead of 1 byte per char like a varchar() variable would be.

What is N in stored procedure?

The N just tells the parser that the string literal should be or is a double-byte (unicode) string. Since your parameter is already of type NVARCHAR the parser knows that what it is.


2 Answers

'N' stands for representing unicode characters.

What this N does is tell the SQL Server that the data which is being passed in is uni-code and not character data. When using only the Latin character set this is not really needed. However if using characters which are not part of the basic Latin character set then the N is needed so that SQL knows that the data being given it is uni-code data.

Original source - http://itknowledgeexchange.techtarget.com/sql-server/whats-up-with-the-n-in-front-of-string-values/

like image 177
Sachin Shanbhag Avatar answered Jan 03 '23 04:01

Sachin Shanbhag


N indicates the string is encoded in Unicode.

like image 39
Bleaourgh Avatar answered Jan 03 '23 06:01

Bleaourgh