Monday, March 19, 2012

Dumb Question - Significance of N

I know this is a stupid question, but I just can't find the proper explanation. I often see the letter N preceding a parameter when executing a stored procedure (ie. exec sp_xxx @.parm = N'test'). What is the significance of the N and when should it be used?

Thanks,
Roby2222It indicates that the data type of the parameter in question is NCHAR, NVARCHAR, or NTEXT, as opposed to CHAR, VARCHAR, or TEXT.|||The N prefix on a string constant forces the string to be interpreted as unicode (16 bit) characters instead of OEM (8 bit) characters.

-PatP|||That is not a dumb question at all. I have wondered that myself as I have seen it in IF EXISTS statements to begin a stored procedure script and so forth, ie:

if exists (select * from dbo.sysobjects
where id = object_id( N'[dbo].[tablename]')
and OBJECTPROPERTY(id, N'IsUserTable') = 1)

Thanks for the question.

ddave|||Thanks for the info. Makes sense...

Roby2222

No comments:

Post a Comment