suppose I have following sql code
DECLARE @colsLoop AS NVARCHAR(MAX) ='[Khulna Titans],[Rajshahi Kings]';
declare @pos as numeric = 0;
declare @len as numeric = 0;
declare @value as varchar(255);
WHILE CHARINDEX(',', @colsLoop, @pos+1)>0
BEGIN
set @len = CHARINDEX(',', @colsLoop, @pos+1) - @pos
set @value = SUBSTRING(@colsLoop, @pos, @len)
print @value
set @pos = CHARINDEX(',', @colsLoop, @pos+@len) +1
end
I cant figure it out why this code only print [Khulna Titans] , I want it print [Rajshahi Kings] after [Khulna Titans], in other words why loop runs only once. Where do I mistake?