存储过程问题???????????

AaronChan 2003-12-23 03:49:09
很简单的一个存储过程,但运行就出问题,在查询分析器下测试没问题,但当用VC ADO调用时就出问题,pSet->IsEof()为真,既没有记录返回。
具体如下:

CREATE PROCEDURE p_sz_foundFaction
@userid int,
@factionname varchar(20)
AS
set nocount on
begin transaction
declare @id int
set @id = -1

select id from t_faction where FactionName = @factionname
if @@rowcount <= 0
begin
insert into t_faction (FactionName, userid) values (@factionname, @userid)
--select @id = id from t_faction where userid = @userid
当执行到这时出错,下面这句不会执行,并且放到到insert前也不执行
update t_user set faction = 1 where userid = @userid
select 0
goto endpos
end

select 1
goto endpos

errorpos:
rollback transaction
return
endpos:
commit transaction
return
GO

...全文
30 41 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
41 条回复
切换为时间正序
请发表友善的回复…
发表回复
AaronChan 2003-12-23
  • 打赏
  • 举报
回复
哎!我重装下SQL试试,今天谢谢你了!!!!
一会给你分!真的太谢谢你了
AaronChan 2003-12-23
  • 打赏
  • 举报
回复
select * from t_user where userid = 510027
当然是返回的这条记录

还是不行,我再看看
AaronChan 2003-12-23
  • 打赏
  • 举报
回复
gmlxf 2003-12-23
  • 打赏
  • 举报
回复
重新启动sqlserver看看吧.
gmlxf 2003-12-23
  • 打赏
  • 举报
回复
1、在查询分析器里面执行:
select * from t_user where userid = 510027
看看结果是什么?

2、

update t_user set faction = 8 where userid = @userid
替换成
update t_user set faction = 8 where userid = 510027


AaronChan 2003-12-23
  • 打赏
  • 举报
回复
改成
update t_sp set spname = 'ksdjfksdjf' where userid = 510008
更新了
为什么t_user就不更性呢?
AaronChan 2003-12-23
  • 打赏
  • 举报
回复
好,我试试
gmlxf 2003-12-23
  • 打赏
  • 举报
回复
你将
update t_user set faction = 8 where userid = @userid
替换成为其他的update 看看吧。我也晕了。
AaronChan 2003-12-23
  • 打赏
  • 举报
回复
就是找不到原因,晕啊!
AaronChan 2003-12-23
  • 打赏
  • 举报
回复
恩!
update t_user set faction = 1 where userid = 510027
这句在查询分析中OK的
gmlxf 2003-12-23
  • 打赏
  • 举报
回复
update t_user set faction = 1 where userid = 510027

不可能啊???

上面在查询分析中总可以了吧?

你仔细检查一下,可能是很小的问题。
AaronChan 2003-12-23
  • 打赏
  • 举报
回复
CREATE PROCEDURE p_get_sale
@userid int,
@salepos int
AS
set nocount on
begin transaction
declare @gid int
declare @name varchar(20)
declare @count int
set @gid = 0
set @name = ''
set @count = 0

select @gid = min(gid) from t_usergoods where userid = @userid and gid > @salepos
if @gid <= 0 or @gid is null
begin
set @salepos = 0
select @gid = min(gid) from t_usergoods where userid = @userid and gid >= @salepos
end

if @gid <= 0 or @gid is null
begin
select 1, @name, @count, @gid
goto endpos
end

update t_user set salepos = @gid where userid = @userid
select @count = count(gid) from t_usergoods where userid = @userid and gid = @gid
select @name = name from t_goods where id = @gid
select 0, @name, @count, @gid
goto endpos

errorpos:
rollback transaction
return
endpos:
commit transaction
return
GO

这是我另外一个存储过程,运行没问题!
AaronChan 2003-12-23
  • 打赏
  • 举报
回复
update t_user set faction = 1 where userid = @userid
if not exists(select 1 from t_faction where FactionName = @factionname)
begin
insert into t_faction (FactionName, userid) values (@factionname, @userid)
--select @id = id from t_faction where userid = @userid
当执行到这时出错,下面这句不会执行,并且放到到insert前也不执行

select 0
goto endpos
end


还是不行,没更新!
AaronChan 2003-12-23
  • 打赏
  • 举报
回复
在存储过程中改成这样后,t_user中另外一条记录更新了,userid为这条的记录没更新!
什么原因?
gmlxf 2003-12-23
  • 打赏
  • 举报
回复
update t_user set faction = 1 where userid = @userid
if not exists(select 1 from t_faction where FactionName = @factionname)
begin
insert into t_faction (FactionName, userid) values (@factionname, @userid)
--select @id = id from t_faction where userid = @userid
当执行到这时出错,下面这句不会执行,并且放到到insert前也不执行

select 0
goto endpos
end

这样呢?
gmlxf 2003-12-23
  • 打赏
  • 举报
回复
update t_user set faction = 8 where userid = @userid
修改成为
update t_user set faction = 8

看看是否更新?
AaronChan 2003-12-23
  • 打赏
  • 举报
回复
这句都执行了的,正常
gmlxf 2003-12-23
  • 打赏
  • 举报
回复
insert into t_faction (FactionName, userid) values (@factionname, @userid)
有执行吗?

在查询分析器里面是否正常?
AaronChan 2003-12-23
  • 打赏
  • 举报
回复
还是没执行,查询分析器里测是执行了,但用VC调就没执行,我试着改成
insert into t_faction (FactionName, userid) values (@factionname, @userid)
select @id = id from t_faction where userid = @userid
update t_user set faction = 8 where userid = @userid
select @id
goto endpos

在VC里看返回的值是正确的,但UPDATA就是没执行!
gmlxf 2003-12-23
  • 打赏
  • 举报
回复
但这么update没执行呢?

会执行。

加载更多回复(21)

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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