Quantcast
Channel: Answers for "Why the below does not work properly"
Viewing all articles
Browse latest Browse all 4

Answer by Cyborg

$
0
0
I hope this will solve your problem DECLARE @t table( ID int identity, Data varchar(50), SplitAt int) Insert into @t Select 'this is a text', 4 union all Select 'this is again a', 5; WITH CTE AS ( Select CONVERT(VARCHAR,LEFT(Data,SplitAt)) SplitedString,STUFF(Data,1,splitAt,'') String, Len(LEFT(Data,SplitAt)) Len,ID FROM @t UNION ALL SELECT CONVERT(VARCHAR,LEFT(String,SplitAt)), STUFF(String,1,SplitAt,'') A ,Len(LEFT(String,SplitAt)) Len , CTE.ID FROM CTE INNER JOIN @t t ON t.ID = CTE.ID WHERE LEN(String)>0 ) SELECT * FROM CTE Order BY ID

Viewing all articles
Browse latest Browse all 4

Trending Articles