I am having a strange problem. I have a function which returns a large string by concatenating several other strings.
In some cases the string is too long and is getting truncated.
For example, there is an instance when a string of length 379999 is supposed to be returned, but what I see is that the string is truncated and the length is only 65536.
I am sure that varchar(MAX) can hold a string greater that 65536, but where am I going wrong here? The function has been shown below.
[UPDATE]
this function is being used in several stored procedures, and the stored procedures are used by the crystal reports to display data.
[UPDATE END]
ALTER FUNCTION [dbo].[GetShipContSernText](
@shipContNum numeric(9)) returns Varchar(MAX) begin
declare serns cursor for
select
serial_number
from
serial_number_view
where
ship_cont_num = @shipContNum
and
template_id is null
open serns;
declare @text varchar(MAX);
declare @serialNumber nvarchar(50);
fetch next from serns into @serialNumber;
while (@@FETCH_STATUS = 0)
begin
-- cannot concat a null string.
if (@text is null)
set @text = @serialNumber;
else
set @text = @text + N', ' + @serialNumber;
end
fetch next from serns into @serialNumber;
end;
close serns;
deallocate serns;
return @text;
end