小蜜蜂的天空

小亲亲制造
自己研究出来的第一个游标

create table #temp(ttype varchar(50),tno int)
declare @temp_type1 varchar(50) 
declare @temp_type2 varchar(50)
declare @temp_no int                 
declare mycursor cursor for select imagetype,imageno from imageproperty_t where
archno='141227'order by imageno 

open mycursor                  

fetch next from mycursor  into @temp_type1,@temp_no  
set @temp_type2=@temp_type1
insert into #temp values(@temp_type1,@temp_no)

while(@@fetch_status=0)   
begin
   if @temp_type1<>@temp_type2
      insert into #temp values(@temp_type1,@temp_no)
   set @temp_type2=@temp_type1
     
    fetch next from mycursor into @temp_type1,@temp_no   
end

close mycursor

select * from #temp order by tno

posted on 2008-03-10 09:13  FilyCks  阅读(146)  评论(0编辑  收藏  举报