SQL游标写法代码
作者:ejoe
select adddate,pic,spic,* from product where code like '102805687%' --56865
select * from crk where ctype=6 and goods='10050709485658'
select * from orders where goods='10050709485658'
SELECT a.goods,a.id,b.code,a.productnum FROM orders a
left join product b on b.id=a.id
where a.goods='10050709485658'
--insert into crk(goods,ctype,code,productnum,actname,comment)
--values('10050709485658',6,'','','ejoe','平台单导错处理')
--
--update product set stock=stock+ ,jtkc=jtkc+ where id=
declare @strCode nvarchar(20)
declare @Num int
declare @intID int
declare mycursor cursor for
SELECT b.code,a.productnum,a.id FROM orders a
left join product b on b.id=a.id
where a.goods='10050709485658'
open mycursor
fetch next from mycursor into @strCode,@Num,@intID
while(@@fetch_status=0)
begin
insert into crk(goods,ctype,code,productnum,actname,comment)
values('10050709485658',6,@strCode,@Num,'ejoe','平台单导错处理');
update product set stock=stock+@Num ,jtkc=jtkc+@Num where id=@intID;
fetch next from mycursor into @strCode,@Num,@intID
end
close mycursor
deallocate mycursor