- 论坛徽章:
- 0
|
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, |
|