0

I've found a lot of questions similar to this, but none of them (or their solutions) seem to fit the behaviour I'm experiencing.

I'm trying to add a lot of text to a row, but it's getting truncated at 4000 characters. I've output this in SSMS as text, and checked the text results size option (it's set to 8000 chars) but I can still seemingly only store 4000 chars.

Simplified example:

CREATE TABLE [dbo].[TestTable](
    [MaxSizeTest] NVARCHAR(MAX) NULL
)

INSERT [dbo].[TestTable](MaxSizeTest)
VALUES (N'1. Definitions' + NCHAR(13) + NCHAR(13) + N'a load more chars' + CHAR(13) + NCHAR(13) + N'you get the idea')

I suspect the issue might be due to my use of carriage return characters, which are needed as the column value is used to populate a textbox.

Wooderson
  • 13
  • 4
  • 1
    `which are needed as the column value is used to populate a textbox` that's not a reason for anything, you need a separation between your model (your db) and your view (the moogical textbox you mentioned). – Blindy Jan 05 '21 at 17:37
  • With nvarchar 8000 bytes make a maximum of 4000 characters (or less if you'r using code points outside the base layer) the actual maximum size of nvarchar(max) is also influenced by the databases compatibility setting. – ub_coding Jan 05 '21 at 17:53
  • If you are concatenating two `nvarchar` and neither are defined as `nvarchar(max)` you will get truncation at `nvarchar(4000)` - you can avoid this issue by making the first element `CAST(N'1. Definitions' AS NVARCHAR(MAX))` instead of literal `N'1. Definitions'` – Martin Smith Jan 05 '21 at 17:57

0 Answers0