What is N?

  • In a function like RIGHT(N'123', 2) which yields '23', what exactly does the N do?  I have seen this in several examples and cannot find documentation on it....(can't really search on N in books online  :crazy

     

  • N denotes a unicode string, Unicode you can read up in BOL. As a start note the difference (only in DATALENGTH) in the script below.

    SELECT

     RIGHT(N'123', 2)

     , RIGHT('123',2)

     , LEN('123')

     , LEN(N'123')

     , DATALENGTH('123')

     , DATALENGTH(N'123')

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Ahhhh....that makes sense now.

    Hopefully SP4 will be out of beta soon and the 'problem' with unicode will be completely resolved.

  • What problem?

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • It's pretty obscure but I was actually having this problem in an application I was working on.... it was giving me a 644 error and I found this article on microsoft's support that said that 'FIX: Error 644 or 8646 may occur during a DELETE or UPDATE against a table that contains a Unicode column with a Latin1_General_BIN collation'.  This is fixed in SP4 beta

    I changed the datatype to varchar from nvarchar and the problem went away...changed it back to nvarchar and it came back.

    http://support.microsoft.com/kb/888799

     

     

  • I wasn't aware of this kb article, you've mentioned. I'll add this to my link library. Thanks!

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply