So there is such a code:
DECLARE @DocJSONGoods nvarchar(MAX)
SELECT @DocJSONGoods = (
SELECT ProductsItems,
DocCDProductsChapterNumber,
DocCDProductsNomenclatureData,
DocCDProductsPurchase,
DocCDProductsAmount,
DocCDProductsValue,
DocCDProductsCountry
FROM @TabChaptersGoods
FOR JSON PATH, ROOT('DocCDProductsList')
)
which pulls 92 records from the table variable (some of which - DocCDProductsNomenclatureData,
DocCDProductsPurchase - are also nvarchar(MAX) and contain JSON) into the nvarchar(MAX) variable. Nothing unusual.
However, in the end we get only 29 full records in JSON and a trimmed 30 right across the nvarchar(max) field containing JSON.
SELECT LEN(@DocJSONGoods) issues 213565. Copy&Paste from SSMS Result Grid variable content of @DocJSONGoods into Notepad++ issues length 72133. Content is Latin and Cyrillic Unicod.
I am writing a completely stupid code where I concatenate records into @DocJSONGoods in a loop and get almost the same result in the end - the 30 entry is cut off (slightly in a different place) but still cut off.
What problem did I encounter? Why is this happening?