Tuesday 29 March 2016

Sql Comma separated id get comma separated result using while loop


// query

declare @strQ varchar(20)='2,3,8',@cnt int=1,@strRe varchar(200)=''
while (@cnt<=LEN(@strQ))
begin
set @strRe=@strRe+cast((select ComboValue1 from TableName where Flag=9 and ComboID=SUBSTRING(@strQ,@cnt,1)) as varchar)+',';
set @cnt=@cnt+2;
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 ,","...