Hi All
I am finding very strange behaviour inside while ...I have big stored procedure which do the calculation on business requirement . In my sp aim using while loop and its resulting duplicates.. I can't paste that proc here because it doing number of things that i will not be able to explain.. but i created same scenario to explain that issue.
declare @min int,@max int,@datarow varchar(2000),@id int
create table #table ( id int, datarow varchar(2000))
set @id= ''
set @datarow=''
insert into #table(id,datarow)
select 1,'hetejajla'
union all
select 4,'hetejajla'
Select * from #table
Select @min=MIN(id) ,@max =MAX(id) from #table
--- Select @min, @max
while (@min<=@max)
begin
Select @id=id,@datarow=datarow from #table where id =@min
Select @id as id ,@datarow as datarow
set @min=@min+1
--select
end
you can see that in my table #table has only two records with ids 1 and 4.
When I run above code which gives me result .
id datarow
1 hetejajla
id datarow
1 hetejajla
id datarow
1 hetejajla
id datarow
4 hetejajla
because of this 2 records converted on 4 records ...This loop shold only display two entries
id datarow
1 hetejajla
id datarow
4 hetejajla
Why this is showing extra records...Pleas suggest me on this tried every possible stuff but can't get rid of the this behaviour.
Vijay is here to learn something from you guys.