0

I'm trying to store a string of 50478 characters length in a nvarchar(max) database field. According to this link, it tells that a nvarchar(max) field can store up to 1 billion characters, but when I tried to store just 50478 characters sql truncates them and doesn't store the full string.

How to solve such a problem?

Do you think that this is just a printing problem with sql server management studio?

Community
  • 1
  • 1
Ibrahim Amer
  • 1,147
  • 4
  • 19
  • 46

1 Answers1

0

You need to ensure that the data being inserted into the field is cast as nvarchar too otherwise you will not be able to achieve what you're looking for.

Take this as an example:

Create table #temp (this nvarchar(max))

insert into #temp values (REPLICATE(cast('a' as nvarchar(max)), 50478))

Select this, Len(this) from #temp

drop table #temp

Also can be viewed on SQL Fiddle here: http://sqlfiddle.com/#!6/551f7/2/0

Christian Barron
  • 2,695
  • 1
  • 14
  • 22