【发布时间】:2012-08-17 04:45:41
【问题描述】:
我正在编写一个存储过程,其中有一个 in update 语句,但我很困惑如何应用这种类型的东西?
我的存储过程是:
ALTER PROCEDURE [dbo].[Payment_SP]
@reciptId varchar(50)=null,
@balPay float=null,
@payDone float=null,
@payDate datetime=null,
@fullfillId_FK varchar(50)=null,
@clintId_FK int=null,
@status varchar(50)=null,
@operation int,
@fullfillId varchar(50)=null
AS
BEGIN
if @operation = 3
BEGIN
UPDATE Recipt
SET balPay = @balPay
WHERE reciptId = @reciptId
if @@rowcount = 0
insert into Recipt(reciptId, balPay, payDone, payDate, fullfillId_FK, clintId_FK)
values(@reciptId, @balPay, @payDone, @payDate, @fullfillId_FK, @clintId_FK)
update Item_Full
set totCost = (select balPay from Recipt)
where fullfillId = @reciptId
if @balPay='0'
BEGIN
update Item_Order
set status = 'CLOSE'
where status = 'FULLFILL'
or status = 'RUNNING'
and orderId = @reciptId
END
ELSE
BEGIN
update Item_Order
set status = 'RUNING'
where status = 'FULLFILL'
and orderId = @reciptId
END
END
END
这里我使用了大量的表格和列。但是我想在Recipt 表中执行此操作,如果余额支付(@balPay = 0),则状态 = 关闭,否则如果有任何余额 > 0,则状态 = 运行
但每次我在付款完成后获得状态都是RUNING。这意味着只有条件语句的 else 部分正在执行,而不是 if 部分
if 语句中应该有什么条件
谢谢
【问题讨论】:
-
没有看到你传入的参数,很难判断。不过,此更新声明看起来是错误的:
update Item_Order set status='CLOSE' where status='FULLFILL' or status='RUNNING' and orderId=@reciptId。您没有像这样将OR语句组合在一起:update Item_Order set status='CLOSE' where (status='FULLFILL' or status='RUNNING') and orderId=@reciptId -
我按照您的指示进行操作,但问题仍然存在
标签: sql sql-server stored-procedures conditional