关于存储过程,急急急!!
declare @BuyQuoteNo_1 [varchar](20)
declare @CreateDate_2 [datetime]
declare @Buyer_3 [int]
declare @DepartmentID_4 [int]
declare @ProductID_6 [int]
declare @Quantity_7 [numeric]
declare @Assigner_8 [int]
declare @BillID [int]
declare @MaxID [int]
declare @MinID [int]
set @buyquoteno_1='0304160001'
set @createdate_2=getdate()
set @buyer_3=3
set @departmentid_4=3
set @productID_6=4
set @quantity_7=10
set @assigner_8=3
set @billid=2
set @maxid=127
set @minid=127
begin
begin transaction T1
declare @varid int
declare @confirmtime datetime
declare @ID_cur cursor
declare @Source [varchar](20)
set @Source='自动生成'
--写询价主表
INSERT INTO [jxc].[dbo].[BuyQuote]
( [BuyQuoteNo],
[CreateDate],
[Buyer],
[DepartmentID],
[Source],
[ProductID],
[Quantity],
[Assigner])
VALUES
(@BuyQuoteNo_1,
@CreateDate_2,
@Buyer_3,
@DepartmentID_4,
@Source,
@ProductID_6,
@Quantity_7,
@Assigner_8)
set @ID_cur=cursor for
select BuyQuoteID from BuyQuote
where BuyQuoteNo=@BuyQuoteNo_1
open @ID_cur
fetch next from @id_cur into @varid
close @ID_cur
deallocate @ID_cur
--用游标取出ID
--写采购询价审核流
set @ConfirmTime=1900-01-01
INSERT buyquoteconfirm
(buyquoteid,StepID,StepName,EmployeeID,MaxAmount,status,ConfirmTime,DepartmentID)
SELECT @varID,StepId,StepName,EmployeeID,MaxAmount,'未审核',@ConfirmTime,@DepartmentID_4
from flow where billID=@BillID and DepartmentID=@DepartmentID_4
--写Buyquoteapply表
insert buyquoteapply
(buyquoteid,productid,rowid,buyapplyid)
SELECT @varid,ProductID,rowid,BuyApplyID
FROM BuyApplyDetail
WHERE (BuyApplyID IN
(SELECT buyapplyid
FROM buyapply
WHERE (buyapplyid BETWEEN @MinID AND @MaxID) AND (Status = '已审核'))) AND
(ProductID = @ProductID_6)
--更改BuyApplyDetail里的标志,0为未下达,1为已下达
update buyapplydetail
set status=1
WHERE (BuyapplyID In (select buyapplyid from buyapply where status='已审核' )) and ((Status = '0')and (productid=@productid_6))
--更改BuyApply里的状态标志,改成已下达
update buyapply
set status='已下达'
WHERE (status='已审核') and (buyapplyid in(select buyapplyid from buyapplydetail where((Status = '0')and (productid=@productid_6))))
commit transaction T1
IF (@@error <> 0)
BEGIN
ROLLBACK TRANsaction T1
END
end
GO
为什么只会执行前四句SQL语句,第五句Update不会执行,我单独运行那一句是好的
请问有没有哪位高手知道是怎么回事啊???