Click to See Complete Forum and Search --> : NVARCHAR confusion???


GoldCoast_Nerd
08-06-2007, 12:23 AM
hey,
i always thought that NVARCHAR was a variable field, so if i set NVARCHAR for a column, it should assign double the number of characters entered as it allows unicode. but NCHAR will only allow 50 characters if the colomn length is set to 50 characters.
I've got a table with a NVARCHAR 500 column, but sometimes when updating or entering data in that field, sql server throws the error ,,

"String or binary data would be truncated."

what is goin on , have i got it all wrong,
any help or advice would be appreciated,
thanks in advance,,

mattyblah
08-07-2007, 11:15 PM
that error means that the value passed exceeds the expected value length. in other words, you are trying to pass a field over nvarchar(x) in length. sorry didnt fully realize what you were trying to do. nvarchar only means unicode, it doesnt mean double length. nvarchar(5) is double the size of varchar(5) (internal storage wise) because unicode characters take 2 bytes to store instead of 1, and not just that but nvarchar(5) can only store 5 characters, just the same as varchar(5).

GoldCoast_Nerd
08-08-2007, 12:06 AM
hey,
thanks for the post,
yeah i sorto' understand now that, NVARCHAR means it assigns max 500 characters but the variable part means that the length is assigned according to the input length, eg.. if i enter data into the colomn which is only 20 characters, it will use up only 20 characters, but in case of NCHAR, the input will b assigned 500 characters irrespective the size of the input..
so i guess the solution is to make the column bigger , or just ensure i don't try and insert or update with data that is more than 500 characters....

thanks mate.:)