What is the "N" prefix for in a ctrierion?

  • It converts the following text to unicode.

  • Having recently migrated from Access Databases to Access Projects and SQL Server, my self-training has been sporadic. I have been coming across syntax like

        WHERE TABLE_NAME = N'vwProductSelect'

    but I don't understand what the N is doing in front of the view name. Could someone please clear this up for me?

    Thanks!

    -- Al

  • Thanks.

    Is it normally necessary, or just good practice?

     

  • Necessary only if your server uses unicode characters (like chinese).  But for global applications like sql server or access, they have to assume that the data can be unicode, that way the application can handle any character on the planet.

  • In some cases it is necessary.

    This will give you an error:

    Exec sp_executesql 'Select @@ServerName'

    This won't:

    Exec

    sp_executesql N'Select @@ServerName'

    The error:

    Msg 214, Level 16, State 2, Procedure sp_executesql, Line 1

    Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'.

     


    My blog: SQL Soldier[/url]
    SQL Server Best Practices:
    SQL Server Best Practices
    Twitter: @SQLSoldier
    My book: Pro SQL Server 2008 Mirroring[/url]
    Microsoft Certified Master: SQL Server, Data Platform MVP
    Database Engineer at BlueMountain Capital Management[/url]

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

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