Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 123»»»

CASTing Expand / Collapse
Author
Message
Posted Monday, May 26, 2008 9:37 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 1:45 AM
Points: 2,570, Visits: 2,428
Comments posted to this topic are about the item CASTing
Post #506647
Posted Tuesday, May 27, 2008 12:03 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, April 3, 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....
######################
Post #506680
Posted Tuesday, May 27, 2008 12:57 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, October 27, 2014 8:18 AM
Points: 2,404, Visits: 2,940
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’! **
Post #506709
Posted Tuesday, May 27, 2008 1:00 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr 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?
Post #506711
Posted Tuesday, May 27, 2008 1:12 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Sunday, April 13, 2014 11:32 AM
Points: 939, Visits: 778
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
Post #506714
Posted Tuesday, May 27, 2008 1:20 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, October 27, 2014 8:18 AM
Points: 2,404, Visits: 2,940
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’! **
Post #506718
Posted Tuesday, May 27, 2008 2:08 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Sunday, April 13, 2014 11:32 AM
Points: 939, Visits: 778
Thankyou Hanshi.

Ive always wondered what the N was for. Thanks.

Matt.
Post #506738
Posted Tuesday, May 27, 2008 2:29 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, June 5, 2014 6:18 AM
Points: 1,140, Visits: 326
Very good question :)

Tests number of areas of knowledge .. what something logically represents vs. what is physically represents

Post #506750
Posted Tuesday, May 27, 2008 6:07 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, October 10, 2014 11:06 AM
Points: 1,570, Visits: 680
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.


Post #506849
Posted Tuesday, May 27, 2008 8:48 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, September 26, 2014 3:34 AM
Points: 202, Visits: 620
Uses per character 16 bits rather than 8.
Post #506970
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse