Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What does N do? 1

Status
Not open for further replies.
Mar 29, 2010
20
GB
What does N do? I'm looking at some code which I understand for the most part, but if I were writing it I wouldnt use N in it, I don't know what N does so was just wondering if someone could explain it to me please.

EXAMPLE:
SELECT * FROM sys.objects WHERE type IN (N'P', N'PC')
 
It converts the string that is immediately after the n to NVARCHAR.

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
ok thanks, i would have thought that a string would automatically be converted to the correct string type though. Does any hardcoded nvarchar need to have an N before the actual string then?
 
I tried the example i gave in the first post with and without the N and i get the same results for both. So why do we need the N?

EXAMPLES:

SELECT * FROM sys.objects WHERE type IN (N'P', N'PC')

SELECT * FROM sys.objects WHERE type IN ('P', 'PC')

 
When you put N' SQL Server knows that the text after that is NVARCHAR. When you didn't put N SQL Server checks the field type and after that it decides if it must convert the text or not.
In other words with N' your query will be a little bit faster :)


Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
I always thought the N meant the string was a unicode string instead of a string based on the Engilsh character set.
 
NVARCHAR is just that - an UNICODE string :)

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top