免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2946 | 回复: 4
打印 上一主题 下一主题

在客户端运行存储过程时,操作失败能不能返回多个不同的值? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-11-07 19:50 |只看该作者 |倒序浏览
if not exists (select * from dbo.sysobjects where id = object_id(N\'[Account]\') and OBJECTPROPERTY(id, N\'IsUserTable\') = 1)
CREATE TABLE [Account] (
        [UserGroup] [int] IDENTITY (1, 1) NOT NULL ,
        [nMoney] [int] NULL
) ON [PRIMARY]
GO

if not exists (select * from dbo.sysobjects where id = object_id(N\'[UserInfo]\') and OBJECTPROPERTY(id, N\'IsUserTable\') = 1)
CREATE TABLE [UserInfo] (
        [UserId] [int] IDENTITY (1, 1) NOT NULL ,
        [UserGroup] [int] NULL
) ON [PRIMARY]
GO

Create Proc get_money @UserId int,@GetMoney int
AS
if @GetMoney>5000
   begin   
   raisError(\'每次取款不能超过5000!\',16,1)
   return (-1)
   end
else if not exists (select Account.UserGroup from UserInfo,Account
                    where UserInfo.UserId=@UserId and Account.UserGroup=UserInfo.UserGroup and Account.nMoney>10000)
   begin  
   raisError(\'帐户存款少于10000,停止取款服务!\',16,1)
   return (-2)
   end
else
   begin
   Update Account set Account.nMoney=Account.nMoney-@GetMoney
   where Account.UserGroup = (select Account.UserGroup from UserInfo,Account
   where UserInfo.UserId=@UserId and Account.UserGroup=UserInfo.UserGroup and Account.nMoney>10000)
   return (1)
end

如上面的表,我建立的存储过程取钱,取钱失败有2个种情况
1是取大于5000
2是帐户少10000
但在客户端只能返回-1,,(用VFP 连接SQL 2000,看到的失败都是-1的)
如果我想他返回取大于5000,返回-1,帐户少于10000,返回-2,怎么做?
我看到一些程序,在raisError还带了个RETURN,不知道我上面的RETURN行不?
**********我刚学SQL 2000,

论坛徽章:
0
2 [报告]
发表于 2005-11-08 13:54 |只看该作者
UP,是不是只能返回-1的啊,

论坛徽章:
0
3 [报告]
发表于 2005-11-08 14:23 |只看该作者
返回一個臨時表呢, 將錯誤在存儲過程中寫到一個表中,
然後執行vfp的調用sql server的語句SQLEXEC(m.gnConnHand,m.sSqlText,\"temptable\"
當返回1時, 表示成功, 再在vfp中判斷是大於5000還是小於10000. 因為在vfp中執行sql server存儲過程時如果返回-1, 則表示你的存儲過程本身錯誤的, 如果是成功的, 你的返回值是1才對.

论坛徽章:
0
4 [报告]
发表于 2005-11-08 15:41 |只看该作者
用OutPut參數取得返回值就可以了.

论坛徽章:
0
5 [报告]
发表于 2005-11-08 15:48 |只看该作者
最初由 DelphiMatrix 发布
[B]用OutPut參數取得返回值就可以了. [/B]

对了,我是刚学SQL 2000,我看到有些例子中有个OUTPUT,不知道有什么作用,你能用OUTPUT把我上面的过程修改一下不?谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP