declare @id nvarchar(500);
declare @fapiao nvarchar(500);
declare p cursor for select jia,jsname from checkps;
open p;
fetch next from p into @id,@fapiao
while @@fetch_status = 0
begin
while charindex(@fapiao,@id) > 0
begin
update checkps set jia=replace(@id,@fapiao,'本人') where jsname=@fapiao;
end;
fetch next from p into @id,@fapiao
end;
close p;
DEALLOCATE p;点击运行,一直提示正在执行查询.查看表checkps,结果还是和以前一样!
declare @fapiao nvarchar(500);
declare p cursor for select jia,jsname from checkps;
open p;
fetch next from p into @id,@fapiao
while @@fetch_status = 0
begin
while charindex(@fapiao,@id) > 0
begin
update checkps set jia=replace(@id,@fapiao,'本人') where jsname=@fapiao;
end;
fetch next from p into @id,@fapiao
end;
close p;
DEALLOCATE p;点击运行,一直提示正在执行查询.查看表checkps,结果还是和以前一样!
--try:declare @id nvarchar(500);
declare @fapiao nvarchar(500);
declare p cursor for select jia,jsname from checkps;
open p;
fetch next from p into @id,@fapiao
while @@fetch_status = 0
begin
while charindex(@fapiao,@id) > 0
begin
set @id=replace(@id,@fapiao,'本人')
update checkps set jia=replace(jia,@fapiao,'本人') where jsname=@fapiao;
end;
fetch next from p into @id,@fapiao
end;
close p;
DEALLOCATE p;
update checkps
set jia=replace(jia,jsname,'本人')
where charindex(jsname,jia) > 0