1

I have a column (col1) with nvarchar(max).

I am trying to do

DECLARE @my_string NVARCHAR(max)
set @my_string = N'test'

UPDATE dbo.tab1 
SET col1 = @my_string + ISNULL(col1, N'')

no luck , I have no idea why it is happening. @marc_s

The string value in col1 getting truncated after 250 characters. This happening in both SQL Server 2005 and 2008.

5
  • I'm not seeing this behavior you're reporting. How and why do you think your column gets truncated at 250 characters?? Commented Jan 4, 2012 at 17:37
  • no triggers. The code is in a sql procedure. Commented Jan 4, 2012 at 19:20
  • Not to second guess you, but, you can run the exact code above and replicate this issue. There's not something else buried in the stored proc you mention that could be truncating your value? Not a buried cast or something? Commented Jan 4, 2012 at 19:55
  • Thanks Jocob. It's too big procedure. Some where down the line string was truncating to 250 chars. Commented Jan 4, 2012 at 20:23
  • SET TEXTSIZE could help Commented Oct 25, 2023 at 11:58

4 Answers 4

3

First of all - I'm not seeing this behavior you're reporting. How and why do you think your column gets truncated at 250 characters?? Are you using a tool to inspect the data that might be truncating the output??

You could check the length of the column:

SELECT col1, LEN(col1) FROM dbo.tab1

Is it really only 250 characters long???

Also: you're mixing VARCHAR (in @my_string) and NVARCHAR (col1) which can lead to messy results. Avoid this!

Next: if you want NVARCHAR(MAX), you need to cast your other strings to that format.

Try this:

DECLARE @my_string NVARCHAR(200)
set @my_string = N'test'

UPDATE dbo.tab1 
SET col1 = CAST(@my_string AS NVARCHAR(MAX)) + ISNULL(col1, N'')

As I said - in my tests, I didn't need to do this - but maybe it works in your case?

Sign up to request clarification or add additional context in comments.

1 Comment

I did select len(col1) from tab1 , it has 250 charecters. Also changed
3

Go to menu - Query --> Query options --> Results --> Text

There is an option Maximun number of characters displayed in each column and mine was defaulted to 256.

Once I set this to 1000 the problem was fixed.

Comments

0

Do you test in SSMS? If so, check in options Query Results > SQL Server > Results to Grid - Maximum characters retrieved > Non XML data. Is there a value 250 or similar?

2 Comments

NO. The value is 65530. I see only 250 from SSMS and from a java application(jdbc)
second guess: what is definition of the table? Is there some sort of check constraint? Like CHECK (DATALENGTH([col1]) <= 250)
0

You're seeing this because the max len of your data in col happens to be 250.

ISNULL ( check_expression , replacement_value ) will truncate the replacement_value to the length of check_expression, per:

https://learn.microsoft.com/en-us/sql/t-sql/functions/isnull-transact-sql

Use COALESCE() instead, which avoids this risk.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.