SQL游标

declare  cursor1  cursor  for  
select Id,Number from [Contract].[dbo].[Apply] where Number != null or Number != ''

declare  @id uniqueidentifier;
declare  @number nchar(20);  
declare  @year  nchar(10);
declare  @companyno  nchar(10);
declare  @contractno int;
 
open cursor1;
fetch next from cursor1 into @id,@number;

while @@FETCH_STATUS = 0
begin     
     select @companyno = [Value] from [dbo].[SplitString2](@number, '-', 1)     
     update [Contract].[dbo].[Apply] set CompanyNo = @companyno where  Id = @id;
     fetch next from cursor1  into @id, @number;
end

close cursor1;
DEALLOCATE cursor1;QL

posted @ 2012-06-11 16:35  宁静.致远  阅读(114)  评论(0编辑  收藏  举报