34,593
社区成员
发帖
与我相关
我的任务
分享
declare @id int,@idnum char(30)
declare cur cursor fast_forward for
select int,innum from rkpc;
open cur
fetch next from cur into @id,@idnum;
if IDNUM IS NOT NULL
begin
update rkpc set 户主='是'
where id=@id
end
else
begin
update rkpc set 户主='否'
where id=@id;
end
fetch next from cur into @id,@idnum;
close cur
要先打开游标才能取数据。
drop table rkpc
GO
create table rkpc(id int, name varchar(10), idnum int,户主 varchar(10))
insert into rkpc values(1 , '张三' , 434300 ,null)
insert into rkpc values(2 , '张三老婆', null ,null)
insert into rkpc values(3 , '张三女儿', null ,null)
insert into rkpc values(4 , '李四' , 434311 ,null)
insert into rkpc values(5 , '李四老婆', null ,null)
insert into rkpc values(6 , '李四儿子', null ,null)
go
select * FROM RKPC
GO
declare @id int,@idnum char(30)
declare cur cursor fast_forward for
select int,innum from rkpc;
open cur
fetch next from cur into @id,@idnum;
while @@FETCH_STATUS=0
BEGIN
if @idnum IS NOT NULL
begin
update rkpc set 户主='是'
where id=@id
end
else
begin
update rkpc set 户主='否'
where id=@id;
end
fetch next from cur into @id,@idnum;
END
close cur
deallocate cur