471,091 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,091 software developers and data experts.

Select * from something where field1 = N'literal'

What exactly is happening when a query is sent using the N in front of
the string to be found?
Under what conditions would someone use the N' in a query?
I have been testing out some chinese text. I set up some fields of
nVarchar, nText and it works with an N. Without the N, it wont work.

N also works with fields of varchar and text for english.

Would this ever cause a problem to a query depending on how the
machines regional settings are set? Why not just put N in all of the
queryies?

If anyone has some ideas, I would be grateful for any and all
information about the N.

Jul 23 '05 #1
1 1525
> Under what conditions would someone use the N' in a query?

The N literal prefix denotes a unicode string. This should be specified
when working with unicode data types (nvarchar, nchar, ntext) but not with
non-unicode data types.
Why not just put N in all of the queryies?
When unlike data types are involved, SQL Server will convert values to the
data type with the highest precedence. It's a good practice to specify
literal values that are appropriate so that expressions are sargable. See
the Books Online <tsqlref.chm::/ts_da-db_2js5.htm> for data type precedence
rules.

You need to be mindful of data type precedence to ensure indexes are used
efficiently. Examine the execution plans of the queries below.

USE pubs

SELECT * FROM authors
WHERE au_lname = 'White'

SELECT * FROM authors
WHERE au_lname = N'White'

--
Hope this helps.

Dan Guzman
SQL Server MVP

<sd********@msn.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com... What exactly is happening when a query is sent using the N in front of
the string to be found?
Under what conditions would someone use the N' in a query?
I have been testing out some chinese text. I set up some fields of
nVarchar, nText and it works with an N. Without the N, it wont work.

N also works with fields of varchar and text for english.

Would this ever cause a problem to a query depending on how the
machines regional settings are set? Why not just put N in all of the
queryies?

If anyone has some ideas, I would be grateful for any and all
information about the N.

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Craig Stadler | last post: by
1 post views Thread by Wayne Deleer | last post: by
5 posts views Thread by Chris Cowles | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.