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

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...