|
Posted by rshivaraman on 05/30/07 17:26
hi :
The following is a sample of how to change a cursor query into a non-
cursor query
Trust this helps
-RS
declare
@where varchar(10),
@when varchar(7),
@who varchar(5),
--@continue int,
@cp_id int,
@count int,
@loop_ctr int,
@loop_max int
--declare c1 cursor
--local
--for
insert into temp_www
([when],[where],who)
(
select distinct
[when],
[where],
who
from cicaprod_duplicates
)
set @loop_max = (select max(www_id) from temp_www)
set @loop_ctr = 1
--open c1
print 'Start loop...'
while(@loop_ctr <= @loop_max)
begin
select @when = [when], @where = [where, @who = who
from temp_www
where www_id = @loop_ctr
print @when+' '+@where+' '+@who
set @count = (select count(cp_id) from cicaprod_nodup
where [when] = @when and [where] = @where and who = @who)
print '@count = '+cast(@count as varchar(5))
set @loop_ctr = @loop_ctr + 1
End -- while
print 'End loop...'
--close c1
--deallocate c1
Navigation:
[Reply to this message]
|