TSQL Prefixing String Literal on Insert - Any Value to This, or Redundant?

Posted by SethO on Stack Overflow See other posts from Stack Overflow or by SethO
Published on 2010-05-27T20:38:47Z Indexed on 2010/05/27 20:41 UTC
Read the original article Hit count: 155

Filed under:
|
|

I just inherited a project that has code similar to the following (rather simple) example:

DECLARE @Demo TABLE
(
    Quantity INT,
    Symbol NVARCHAR(10)
)

INSERT INTO @Demo (Quantity, Symbol)
SELECT 127, N'IBM'

My interest is with the N before the string literal.

I understand that the prefix N is to specify encoding (in this case, Unicode). But since the select is just for inserting into a field that is clearly already Unicode, wouldn't this value be automatically upcast?

I've run the code without the N and it appears to work, but am I missing something that the previous programmer intended? Or was the N an oversight on his/her part?

I expect behavior similar to when I pass an int to a decimal field (auto-upcast). Can I get rid of those Ns?

© Stack Overflow or respective owner

Related posts about tsql

Related posts about unicode