Following is complete sql script for your desire results...
Here I consider
CREATE TABLE [dbo].[t1](
[id] [int] NULL,
[Result] [varchar](50) NULL
)
as Table1
and
CREATE TABLE [dbo].[t2](
[id] [int] NULL,
[description] [nvarchar](50) NULL
)
as table2
and bellow is your complete sql server script.....
declare @Table table(Recid int identity, id int,Descp varchar(50))
create table #temp( id int,Descp varchar(50))
insert into @Table
select * from t1
declare @i int,@cnt int,@Str varchar(50),@Ids int,@StrQuery varchar(max)
select @cnt=count(*),@i=1 from @Table
while @i<=@cnt
begin
select @str='(' + Descp +')',@Ids=id from @Table where Recid=@i
set @StrQuery=' insert into #temp select ' +cast( @Ids as varchar(10)) + ', description from t2 where cast(id as varchar(10)) in ' + @str
exec (@StrQuery)
set @i=@i+1
end
declare @Table1 table(Recid int identity, id int,Descp varchar(50))
insert into @Table1(id)
select distinct id from #temp
declare @Id int
select @cnt=count(*),@i=1 from @Table1
while @i<=@cnt
begin
select @Id=id from @Table1 where RecID =@i
set @str =''
SELECT @str = COALESCE(@str + ',', '') + Descp
FROM #temp where id=@id
update @Table1 set Descp =@str where id=@id
set @i=@i+1
end
select id,RIGHT(RTRIM(Descp), LEN(Descp) - 1) from @Table1