[Solved] Parse comma separated string, split array into chunks, then transpose

So long as the number of rows is known, it only takes: a regex to split the string on comma-spaces which immediately follow a one-or-more digits or a word starting with an uppercase letter, a call of array_chunk() and array_map() (with a null callback and data spreading) to “transpose” the data. Code: (Demo) $string = … Read more

[Solved] Dynamic convert Row to Column using group by

try this, create table #tmp (MR_ID varchar(50),DR_ID int) insert into #tmp VALUES (‘MR_123’, 1),(‘MR_123’, 3),(‘MR_124’, 4),(‘MR_124’, 5) ,(‘MR_124’, 6),(‘MR_125′, 0) declare @DRCol varchar(50) declare @Prefix varchar(20)=’DR_’ ;With CTE as ( select * ,ROW_NUMBER()over(partition by MR_ID order by DR_ID)rn from #tmp ) select top 1 @DRCol=stuff((select ‘,’+'[‘+@Prefix+cast(rn as varchar)+’]’ from cte c1 where c.mr_id=c1.mr_id for xml … Read more