I have a varchar(max)
defined but it is truncating the string.
I have searched for the solution and found that all the new values assigned or appended to the string should be cast to varchar(max)
but it still didn't help.
Here is my code:
DECLARE @tr VARCHAR(MAX) = ''
SELECT
@tr = CAST(CAST(@tr AS VARCHAR(MAX)) +
CAST(ISNULL(CONCAT
(
'<tr>',
'<td class="dataline">',t.ComponentEquipmentNumber,'</td>',
'<td class="dataline">',t.ComponentDescription,'</td>',
'<td class="dataline">',t.ReceiverCustodian,'</td>',
'<td class="dataline">',t.[Location],'</td>',
'<td class="dataline">',t.ParentSystemNumber,'</td>',
'<td class="dataline">',t.ParentSystemLocation,'</td>',
'<td class="dataline">',t.RootSystemNumber,'</td>',
'<td class="dataline">',t.RootSystemLocation,'</td>',
'<tr/>'
),'') AS VARCHAR(MAX)) AS VARCHAR(MAX))
FROM
#TempFinal t
ORDER BY
EquipmentId
You can see I have put cast to VARCHAR(MAX)
on all levels just to make it works, but it still didn't work.
And when I try to print the length of the string print len(@tr)
, it returns this strange number 76788
which is not even equal to 8000
characters of VARCHAR(MAX)
, not getting the logic of this number.
Please help!