Trydeclare @table table(id int identity(1,1),[Values] varchar(200))insert into @tableselect '1,2,3,4' union allselect '1,2' union allselect '8,9' declare @i intselect @i=max(len([values])-len(replace([values],',',''))) from @tableprint @iupdate @tableset [values]=[values]+replicate(',',@i-1) from @tablewhere len([values])-len(replace([values],',',''))<>@ideclare @s varchar(8000), @data varchar(8000)select @s=''while exists (Select * from @table where [values]>@s)Begin Select @s=min([values]) from @table where [values]>@s select @data=''''+replace(@s,',',''',''')+'''' exec('select '+@data)EndMadhivananFailing to plan is Planning to fail