Tuesday 29 March 2016

Check and split string with while loop in sql


// Query

declare @strQ varchar(20)='0001010100',@cnt int=1,@strRe varchar(10)=''
while (@cnt<=13)
begin
if(SUBSTRING(@strQ,@cnt,1)=1)
begin
set @strRe=@strRe+cast(@cnt as varchar)+',';
end
set @cnt=@cnt+1;
end

print @strRe

// Result

No comments:

Post a Comment

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...