关于存储过程,急急急!!

sharksyy 2003-04-16 12:58:22

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不会执行,我单独运行那一句是好的
请问有没有哪位高手知道是怎么回事啊???
...全文
104 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
sharksyy 2003-04-16
  • 打赏
  • 举报
回复
楼上这位大哥,你改的没有用啊?
还有啊,执行后怎么样提交啊?
能不能写出来我看看啊?
pengdali 2003-04-16
  • 打赏
  • 举报
回复
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)


select top 1 @varid=BuyQuoteID from BuyQuote where BuyQuoteNo=@BuyQuoteNo_1


--写采购询价审核流
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

IF (@@error <> 0)
ROLLBACK TRANsaction T1


--写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)

IF (@@error <> 0)
ROLLBACK TRANsaction T1


update buyapplydetail
set status=1
WHERE (BuyapplyID In (select buyapplyid from buyapply where status='已审核' )) and ((Status = '0')and (productid=@productid_6))

IF (@@error <> 0)
ROLLBACK TRANsaction T1



--更改BuyApply里的状态标志,改成已下达
update buyapply
set status='已下达'
WHERE (status='已审核') and (buyapplyid in(select buyapplyid from buyapplydetail where((Status = '0')and (productid=@productid_6))))

IF (@@error <> 0)
ROLLBACK TRANsaction T1


commit transaction T1

end
GO
愉快的登山者 2003-04-16
  • 打赏
  • 举报
回复
因为第4句执行后,没有提交;第5句要使用前一个表,所以被锁住,不能执行。

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧