|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Today @ 1:51 AM
Points: 1,971,
Visits: 1,821
|
|
| Comments posted to this topic are about the item CASTing
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Tuesday, April 03, 2012 3:37 AM
Points: 369,
Visits: 161
|
|
Hi All..
declare @c varchar(8000) set @c = N'hello'
In the above statement there is the "N" mentioned in the beginning of the string.. what does it mean exactly???
Is it indirectly enforcing the casting of varchar into Nvarchar????
Can any one explain??
Thanks in advance..
Ramkumar . K Senior Developer ###################### No Surrender... No Give Up.... ######################
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 3:16 AM
Points: 1,117,
Visits: 1,149
|
|
Hi,
You can find this information about the N-prefix in the BOL: Unicode string constants that appear in code executed on the server, such as in stored procedures and triggers, must be preceded by the capital letter N. This is true even if the column being referenced is already defined as Unicode. Without the N prefix, the string is converted to the default code page of the database. This may not recognize certain characters.
Hans
** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, March 16, 2011 1:03 PM
Points: 582,
Visits: 14
|
|
| Where does it say anything about 4000?
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Thursday, February 07, 2013 3:07 AM
Points: 890,
Visits: 774
|
|
The answer says it's cast as nvarchar(4000) initially, but i too dont see how?
Am i missing something, or is there a typo?
Matt
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 3:16 AM
Points: 1,117,
Visits: 1,149
|
|
Because of the N-prefix the value is cast to NVarChar. The NVarChar(MAX) can contain a maximum of 4000. BOL: nvarchar [ ( n | max ) ] Variable-length Unicode character data. n can be a value from 1 through 4,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size, in bytes, is two times the number of characters entered + 2 bytes. The data entered can be 0 characters in length. The SQL-2003 synonyms for nvarchar are national char varying and national character varying.
** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Thursday, February 07, 2013 3:07 AM
Points: 890,
Visits: 774
|
|
Thankyou Hanshi.
Ive always wondered what the N was for. Thanks.
Matt.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Tuesday, January 29, 2013 4:08 AM
Points: 1,140,
Visits: 306
|
|
Very good question :)
Tests number of areas of knowledge .. what something logically represents vs. what is physically represents
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 7:30 AM
Points: 1,566,
Visits: 600
|
|
Just to clarify HanShi's posting - NVARCHAR(MAX) is not limited to 4000 characters. The maximum length of VARCHAR(MAX) is 2^31 -1 (2,147,483,647) characters.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Wednesday, February 20, 2013 4:14 AM
Points: 198,
Visits: 588
|
|
| Uses per character 16 bits rather than 8.
|
|
|
|