Link to home
Start Free TrialLog in
Avatar of KentDBerry
KentDBerry

asked on

Why is Concatenation of 2 nvarchar(max) values truncating?

I'm using a cursor to concatenate all the values of the OriginalComments column into one variable called @Comments.  Both are declared as nvarchar(max).  Why does the line where concatenation occurs result in an empty string?

Declare @Comments nvarchar(max)
Declare @Question nvarchar(max)
Declare @DisplayOrder nvarchar(max)
Declare @OriginalComments nvarchar(max)
 
OPEN Comments_Cursor
FETCH NEXT FROM Comments_Cursor INTO @Question, @DisplayOrder, @OriginalComments
 
WHILE @@FETCH_STATUS = 0
BEGIN
	Select @Comments = rtrim(@Comments) + rtrim(@OriginalComments) + '; '
	Print @OriginalComments
	Print rtrim(@Comments)
FETCH NEXT FROM Comments_Cursor INTO @Question, @DisplayOrder, @OriginalComments
END
CLOSE Comments_Cursor
DEALLOCATE Comments_Cursor
 
Print @Comments

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of pivar
pivar
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of KentDBerry
KentDBerry

ASKER

Thanks Peter.  That did it.