A user of one of our databases is trying to send an UPDATE query to the SQL Server 2005 database, and the text will be truncated unexpectedly.
The truncated field is VARBINARY (MAX) and is used to store HTML text.
Request approximately:
UPDATE Story SET mainText = CONVERT (VARBINARY (MAX), '[...5000 chars of text...]' + char(47) + char(47) + '[...3000 chars of text...]' + char(47) + char(47) + '[...5000 chars of text...]') WHERE storyId = 123456
What I discovered after some experimentation is that when deleting the string concatenation, the query works as expected, and the field is not truncated.
I managed to get around the restriction and save the concatenation by wrapping each individual line in CAST to VARCHAR (MAX), so there is an option if the user considers that char () is to be used.
I think that whenever an concatenation operator is used, an implicit conversion occurs with VARCHAR, and that the implicit conversion is apparently limited to VARCHAR (8000) instead of VARCHAR (MAX). Thus, before the string is even sent to the CONVERT function, it is already truncated to 8000 characters.
If I am right, is there a way to change this behavior?
If there is no way to change the behavior, is there any other way to handle the problem besides CAST?
source share