在C#修改数据
问题描述:把EXCEL数据导入数据库中 "表1 ",要修改表1以后才能把表1数据复制到表2中在, "表1 "有ID字段是自增字段, "表1 "有PID字段,要做修改的字段,PID字段修改条件是查询表2中PID最大值,来修改表1中PID 条件是表1中ID是最小,作一个循环来修改.
------解决方案--------------------试试可不可以
CREATE proc bb
as
declare @id int ,@maxpid int
set @id=0
set @maxpid=0
declare pid cursor for
select id from a where pid is null order by id
for read only
open pid
fetch next from pid into @id
while @@fetch_status = 0
begin
select @maxpid=isnull(max(pid),0)+1 from b
update a set pid=@maxpid from a where id=@id
insert into b select pid ,title,Num from a where id=@id
fetch next from pid into @id
end
CLOSE pid
DEALLOCATE pid
GO