Dear All,I recently had a need to concatenate values of a text column over multiple rows. I did it by creating a function that is defined as follows:CREATE function fn_ConcatSiteInspectionObservations( @site_inspection_schedule_id int, @site_id int)returns varchar(8000)as begin declare @txtObservations varchar(8000);set @txtObservations = '';select @txtObservations = @txtObservations + --coalesce(convert(varchar(8000), todos), '') case coalesce(convert(varchar(8000), observations), '') when 'None.' then '' else coalesce(convert(varchar(8000), observations), '') endfrom site_inspectionwhere site_inspection_schedule_id = @site_inspection_schedule_id and site_id = @site_idreturn @txtObservations;end
This function can then be included in the field clause of a select statement such as:select site_inspection_schedule_id, site_id, dbo.fn_ConcatSiteInspectionObservations(site_inspection_schedule_id, site_id) as observationsfrom site_inspectionwhere ...
My problem is results of this function are always truncated to 256 characters. I have already defined this function to return varchar(8000). However, that specification seem to have no effect.Please help.Thanks.Roslen