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

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...