这样存储过程这么写?急!!!!
表结构如下:
table 1 table2
p_id n_id type number n_id t1 t2 t3 t4
1 xy1 t1 1 xy1 1 0 1 0
2 xy1 t2 2 xy2 1 1 1 1
1 xy2 t1 3 xy3 1 1 1 1
3 xy2 t4 4 xy4 1 1 1 1
select * from table1 where p_id=1
if 查询结果不为空
begin
while(查询结果的行数)
begin
if type=t1
update table2 set t1=t1-从table1中查询出的number字段 where n_id=从table1中查询出的n_id
if type=t2
update table2 set t2=t2-从table1中查询出的number字段 where n_id=从table1中查询出的n_id
if type=t3
update table2 set t2=t3-从table1中查询出的number字段 where n_id=从table1中查询出的n_id
if type=t4
update table2 set t2=t4-从table1中查询出的number字段 where n_id=从table1中查询出的n_id
end
end