奇怪的现象:调用存储过程中无法更新表,但是直接执行SQL语句确可以更新。请各位指教!

ranman 2003-09-29 01:44:15
存储过程:
CREATE PROCEDURE p_q_cash_comeback
@casher varchar(10),
@cause varchar(100),
@owner int
AS
--set nocount on
--begin transaction
declare @cashtime datetime,
@packetnum int
begin
select top 1 @cashtime=cashtime ,@packetnum=packetnum from t_q_cashinfo where userid=@owner order by cashtime desc

update t_q_cswin
set stats=1,cashtime=NULL
where cashtime=@cashtime and owner=@owner

update t_q_userinfo
set packnum=packnum+@packetnum
where userid=@owner
delete from t_q_cashinfo where cashtime=@cashtime and userid=@owner

insert into t_q_cash_bak(cashtime,owner,comebacktime,casher,cause) values(@cashtime,@owner,getdate(),@casher,@cause)
end
--endpos:
--commit transaction
--errorpos:
--rollback transaction
--eturn
GO

我在查询分析器里如下执行存储过程:
exec p_q_cash_comeback 'ligang','ligang',1011
结果无法更新t_q_cswin表,但是其他的成功执行了。
我又在查询分析器里执行如下的语句:
update qcs..t_q_cswin
set stats=1,cashtime=NULL
where owner=1011
确能成功的修改,请问这是为什么?(cashtime字段允许空)
...全文
74 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiandanyu 2003-09-29
  • 打赏
  • 举报
回复
再重申一遍aierong(皑婀瑢-数据库XML.NET联盟会处长)的意思:
存储过程中有2个约束条件,查询分析器中执行的约束条件只有一个
ranman 2003-09-29
  • 打赏
  • 举报
回复
@cashtime 变量的值不可能为null
jiandanyu 2003-09-29
  • 打赏
  • 举报
回复
select top 1 @cashtime=cashtime ,@packetnum=packetnum from t_q_cashinfo where userid=@owner order by cashtime desc
也许是@cashtime=null,那么条件cashtime=@cashtime就不对了,只能是is null
ranman 2003-09-29
  • 打赏
  • 举报
回复
是不是存储过程里的更新语句里不能有2个条件约束?条件cashtime=@cashtime对呀
txlicenhe 2003-09-29
  • 打赏
  • 举报
回复
CREATE PROCEDURE p_q_cash_comeback
@casher varchar(10),
@cause varchar(100),
@owner int
AS
--set nocount on
begin transaction
declare @cashtime datetime,
@packetnum int
begin
select top 1 @cashtime=cashtime ,@packetnum=packetnum from t_q_cashinfo where userid=@owner order by cashtime desc

update t_q_cswin
set stats=1,cashtime=NULL
where cashtime=@cashtime and owner=@owner
if @@error <> 0 goto errorpos
update t_q_userinfo
set packnum=packnum+@packetnum
where userid=@owner
if @@error <> 0 goto errorpos
delete from t_q_cashinfo where cashtime=@cashtime and userid=@owner
if @@error <> 0 goto errorpos
insert into t_q_cash_bak(cashtime,owner,comebacktime,casher,cause) values(@cashtime,@owner,getdate(),@casher,@cause)
if @@error <> 0 goto errorpos
commit transaction
return 0
errorpos:
rollback transaction
return -1
GO
aierong 2003-09-29
  • 打赏
  • 举报
回复
CREATE PROCEDURE p_q_cash_comeback
@casher varchar(10),
@cause varchar(100),
@owner int
AS
--set nocount on
--begin transaction
declare @cashtime datetime,
@packetnum int
begin
select top 1 @cashtime=cashtime ,@packetnum=packetnum from t_q_cashinfo where userid=@owner order by cashtime desc

update t_q_cswin
set stats=1,cashtime=NULL
where owner=@owner

update t_q_userinfo
set packnum=packnum+@packetnum
where userid=@owner
delete from t_q_cashinfo where cashtime=@cashtime and userid=@owner

insert into t_q_cash_bak(cashtime,owner,comebacktime,casher,cause) values(@cashtime,@owner,getdate(),@casher,@cause)
end
--endpos:
--commit transaction
--errorpos:
--rollback transaction
--eturn
GO
aierong 2003-09-29
  • 打赏
  • 举报
回复
update t_q_cswin
set stats=1,cashtime=NULL
where cashtime=@cashtime and owner=@owner



你存储过程里面的更新语句里面有2个条件约束啦
是不是这个条件cashtime=@cashtime不对

22,206

社区成员

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

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