我一般写游标都是把这段语句复制过去,在再上面进行修改,这样的话就不会出现格式上的问题等等...
declare @djlsh4 int,@djbth int,@cpxh int ------声明变量
declare cursor_name cursor for-------创建游标
select distinct djlsh,djbth,cpxh from table_name
open cursor_name
fetch next from cursor_name into @djlsh4,@djbth,@cpxh
while (@@fetch_status=0)
begin
if not exists(select 1 from gjjcbs where djlsh=@djlsh4 and djbth=@djbth and ztf='启用')
begin
update gjjcbb set zt='停用' where djlsh=@djlsh4 and djbth=@djbth
end
fetch next from cursor_name into @djlsh4,@djbth,@cpxh
end
close cursor_name--关闭游标
deallocate cursor_name--删除游标