Hi All,

I request you to kindly go through this below code.

If you can see that @query1 has the complete string(select statement)
I want that a value should be returned from the query which is the moduleid.
The same thing should get affected for @query2.

I want to compare both the retuned results and then insert them into the temporary table.




SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE Procedure a1234 @id varchar(40)
AS
-- Turn off count return.
Set NoCount On
declare @query1 varchar(200),
@query2 varchar(200),
@val1 varchar(50),
@val2 varchar(50),
@val3 varchar(50),
@i int,
@j int,
@cnti int,
@cntj int,
@p varchar(40),
@q varchar(40),
@mod1 int,
@mod2 int
set @val1 = '%'+@id+'%'
set @val2 = @id+'%'
set @val3 = '%'+@id
set @i = 1
select @cnti = count(*) from module_master
select @cntj = count(*) from module_master
WHERE mentorid like @val1 OR mentorid LIKE @val2 OR mentorid LIKE @val3
drop table #myTempTable
CREATE TABLE #myTempTable
(
moduleid varchar(200),
checked VARCHAR(20)
)
while (@i<=@cnti)
begin
set @p = @i
set @query1 = 'select top 1 moduleid from (select top ' + cast(@p as varchar(40)) + '* from module_master order by moduleid) q1 order by moduleid desc'
exec(@query1)
--select @mod1 = cast(@query1 as int)
set @j = 1
while(@j<=@cntj)
begin
set @q = @j
set @query2 = 'select top 1 moduleid from (select top ' + cast(@q as varchar(40)) + '* from module_master WHERE mentorid like '+ @val1 +'OR mentorid LIKE '+ @val2 +' OR mentorid LIKE '+ @val3+' order by moduleid) q order by moduleid desc'
exec(@query2)

if(@query1= @query2)
begin
insert into #myTempTable values(@query1,'True')
end
else
begin
insert into #myTempTable values(@query1,'False')
end
set @j = @j +1
end
set @i = @i +1
end
select moduleid,checked from #myTempTable
go
SET NOCOUNT OFF

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

Kindly help me at the earliest...

Thanks in advance