declare @CmdNo int, @CarNo varchar(200) declare c1 cursor for select CarNo from tmp_UserCommand open c1 fetch next from c1 into @CarNo begin transaction while @@Fetch_Status=0 begin
set identity_insert cmd_UserCommand on insert cmd_UserCommand (写上字段列表) select * from tmp_UserCommand where CarNo=@CarNo select @CmdNo=@@identity insert cmd_UserCommandDetail (CmdNo,COrderID,BarCode,amount,AreaCode) select @CmdNo,COrderID,BarCode,amount,AreaCode from tmp_UserCommandDetail where CarNo=@CarNo update sys_Car set UsableFlag=1 where carno=@CarNo fetch next from c1 into @CarNo end close c1 DEALLOCATE c1 update cmd_CustomerGoodsDetail set CommandFlag=1 from tmp_UserCommandDetail a where cmd_CustomerGoodsDetail.COrderID=a.COrderID and cmd_CustomerGoodsDetail.BarCode=a.BarCode commit transaction;
declare c1 cursor for select CarNo from tmp_UserCommand
open c1
fetch next from c1 into @CarNo
begin transaction
while @@Fetch_Status=0
begin
set identity_insert cmd_UserCommand on
insert cmd_UserCommand (写上字段列表)
select * from tmp_UserCommand where CarNo=@CarNo
select @CmdNo=@@identity
insert cmd_UserCommandDetail (CmdNo,COrderID,BarCode,amount,AreaCode)
select @CmdNo,COrderID,BarCode,amount,AreaCode
from tmp_UserCommandDetail where CarNo=@CarNo
update sys_Car set UsableFlag=1 where carno=@CarNo
fetch next from c1 into @CarNo
end
close c1 DEALLOCATE c1
update cmd_CustomerGoodsDetail set CommandFlag=1 from tmp_UserCommandDetail a
where cmd_CustomerGoodsDetail.COrderID=a.COrderID and
cmd_CustomerGoodsDetail.BarCode=a.BarCode
commit transaction;
因为标识列ID是不允许写的.