I have the below input table
Input
ID Row Data
1 1 a2b
1 2 p1d1
2 1 abcd
Expected Output
ID RowCol Chars
1 a1 a
1 b1 X
1 c1 X
1 d1 b
1 a2 p
1 b2 X
1 c2 d
1 d2 X
2 a1 a
2 b1 b
2 c1 c
2 d1 d
Each numbers in the data column will be treated as that many X's. So if the expand the first resord which is 'a2b' it becomes aXXB. that is the length will be 4. Representing in columns it will be a, b ,c and d. And since, it is in the first row, therefore, the output will be
ID RowCol Chars
1 a1 a
1 b1 X
1 c1 X
1 d1 b
The ddl is as under
Declare @t table(ID int , Row int, Data varchar(10))
Insert into @t
Select 1, 1,'a2b' Union All Select 1,2,'p1d1' Union All Select 2,1,'abcd'
Looking for a cte based solution.
Thanks in advance