tsql - how to sort data on a comma separated list in ssrs report -


i have comma separated list on cell made coalesce keyword below:

select      @relatorfirmdeals = coalesce(@relatorfirmdeals + ', ', '') + isnull(h.dtm_unittypename, '') + '-' + isnull(cast(h.dtm_unitno nvarchar(5)), '')      filteredopportunity o  inner join      filtereddtm_unit h on o.pcrm_homeid = h.dtm_unitid     o.dtm_project = @projectid ,      not o.pcrm_rdeid null ,     o.statuscode = 265780001 

how can sort list?

thanks

here approach work you.

first, grab udf_split user-defined function (udf) this question's answer. udf pass delimited string parameter, , return table row each value.

once have in place, need use udf in following manner.

declare @relatorfirmdeals varchar(8000) = 'g2-18, g3-21, g2-13, g-15, g1-16, g2-17, g3-9, g1-11, g2-12, b2-22, b-23, b-24, b1-25, b-28, b-29, b-30, b2-31, f2-69, f-70, f-71, f-72'  select ltrim(stuff((select ', ' + rtrim(ltrim(value))     dbo.udf_split(@relatorfirmdeals, ',')     order 1 xml path ('')), 1, 2, '')); 

this resulting string:

b-23, b-24, b-28, b-29, b-30, b1-25, b2-22, b2-31, f-70, f-71, f-72, f2-69, g-15, g1-11, g1-16, g2-12, g2-13, g2-17, g2-18, g3-21, g3-9

hope helps out.


Comments