请高手们帮忙看看这个存储过程我该怎么更改。

hiu9 2004-04-24 10:26:07
请高手们帮忙看看这个存储过程我该怎么更改。
create proc dp_sumarmyfund
@personal nvarchar(255),
@dateyear_1 smalldatetime,
@dateyear_2 smalldatetime,
@sum_12 decimal(6,3)output,
@sumarmy decimal(6,3)output
as
select Armyfund.Itemnumber,Armyfund.Cliquevalue,Armyfund.Criterion,Armyfund.PYCCBH,personaltable.Itemnumber,Personaltable.countnum,personaltable.PYCCBH,personaltable.datayear
from personaltable,Armyfund
where Personaltable.Itemnumber=Armyfund.Itemnumber and Personaltable.PYCCBH=Armyfund.PYCCBH
begin
if personaltable.Itemnumber=Armyfund.Itemnumber and personaltable.Xh=@personal and dateyear between @dateyear_1 and @dateyear_2
select @sum_12
if Arrmyfund.Itemnumber=Personal.Itemnumber and Armyfund.PYCCBH=Personaltable.PYCCBH
select @sumarmy=@sum_12*Armyfund.Criterion
select @sumarmy
else
raiserror('该记录不存在.',16,1)
end
-----------------------------------------------------------
服务器: 消息 156,级别 15,状态 1,过程 dp_sumarmyfund,行 17
在关键字 'else' 附近有语法错误。
...全文
50 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hiu9 2004-04-25
  • 打赏
  • 举报
回复
谢谢大家了!!
hiu9 2004-04-25
  • 打赏
  • 举报
回复
试如下代码:表已在库中存在
create proc dp_sumarmyfund
@personal nvarchar(255),
@dateyear_1 smalldatetime,
@dateyear_2 smalldatetime,
@sum_12 decimal(6,3)output,
@sumarmy decimal(6,3)output
as
select Armyfund.Itemnumber,Armyfund.Cliquevalue,Armyfund.Criterion,Armyfund.PYCCBH,personaltable.Itemnumber,Personaltable.countnum,personaltable.PYCCBH,personaltable.datayear
from personaltable,Armyfund
where Personaltable.Itemnumber=Armyfund.Itemnumber and Personaltable.PYCCBH=Armyfund.PYCCBH
begin
if personaltable.Itemnumber=Armyfund.Itemnumber and personaltable.Xh=@personal and dateyear between @dateyear_1 and @dateyear_2
select @sum_12
if
Arrmyfund.Itemnumber=Personal.Itemnumber and Armyfund.PYCCBH=Personaltable.PYCCBH
begin
select @sumarmy=@sum_12*Armyfund.Criterion
select @sumarmy

end
else
begin
raiserror('该记录不存在.',16,1)
end
end
hiu9 2004-04-24
  • 打赏
  • 举报
回复
我试后
服务器: 消息 156,级别 15,状态 1,过程 dp_sumarmyfund,行 17
在关键字 'else' 附近有语法错误。
该错误已不存在但出现了下面的错误,这种连接是不是非得需要有主键与外键的关系呢?
我又该怎么去处理呢?麻烦个位高手们再不厌其烦的给解答一下后给分。
列前缀 'personaltable' 与查询中所用的表名或别名不匹配。
服务器: 消息 107,级别 16,状态 1,过程 dp_sumarmyfund,行 12
列前缀 'Armyfund' 与查询中所用的表名或别名不匹配。
服务器: 消息 107,级别 16,状态 1,过程 dp_sumarmyfund,行 12
列前缀 'personaltable' 与查询中所用的表名或别名不匹配。
服务器: 消息 107,级别 16,状态 1,过程 dp_sumarmyfund,行 14
列前缀 'Arrmyfund' 与查询中所用的表名或别名不匹配。
服务器: 消息 107,级别 16,状态 1,过程 dp_sumarmyfund,行 14
列前缀 'Personal' 与查询中所用的表名或别名不匹配。
服务器: 消息 107,级别 16,状态 1,过程 dp_sumarmyfund,行 14
列前缀 'Armyfund' 与查询中所用的表名或别名不匹配。
服务器: 消息 107,级别 16,状态 1,过程 dp_sumarmyfund,行 14
列前缀 'Personaltable' 与查询中所用的表名或别名不匹配。
服务器: 消息 107,级别 16,状态 1,过程 dp_sumarmyfund,行 17
列前缀 'Armyfund' 与查询中所用的表名或别名不匹配。
internetcsdn 2004-04-24
  • 打赏
  • 举报
回复
create proc dp_sumarmyfund
@personal nvarchar(255),
@dateyear_1 smalldatetime,
@dateyear_2 smalldatetime,
@sum_12 decimal(6,3)output,
@sumarmy decimal(6,3)output
as
select Armyfund.Itemnumber,Armyfund.Cliquevalue,Armyfund.Criterion,Armyfund.PYCCBH,personaltable.Itemnumber,Personaltable.countnum,personaltable.PYCCBH,personaltable.datayear
from personaltable,Armyfund
where Personaltable.Itemnumber=Armyfund.Itemnumber and Personaltable.PYCCBH=Armyfund.PYCCBH
begin
if personaltable.Itemnumber=Armyfund.Itemnumber and personaltable.Xh=@personal and dateyear between @dateyear_1 and @dateyear_2
select @sum_12
if
Arrmyfund.Itemnumber=Personal.Itemnumber and Armyfund.PYCCBH=Personaltable.PYCCBH
--begin
select @sumarmy=@sum_12*Armyfund.Criterion
select @sumarmy

--end
else
--begin
raiserror('该记录不存在.',16,1)
--end
end
shuichangliu 2004-04-24
  • 打赏
  • 举报
回复
养成良好的习惯,IF后面不管有几句话
最好一律加上begin end
这样肯定没错
shuichangliu 2004-04-24
  • 打赏
  • 举报
回复
select @sumarmy=@sum_12*Armyfund.Criterion
select @sumarmy

应该改为
begin
select @sumarmy=@sum_12*Armyfund.Criterion
select @sumarmy
end
shuichangliu 2004-04-24
  • 打赏
  • 举报
回复
decalre @A fieldType,@B fieldType,.......

select @A=Armyfund.Itemnumber,,@B=Armyfund.Cliquevalue,Armyfund.Criterion,Armyfund.PYCCBH,personaltable.Itemnumber,Personaltable.countnum,personaltable.PYCCBH,personaltable.datayear
from personaltable,Armyfund
where Personaltable.Itemnumber=Armyfund.Itemnumber and Personaltable.PYCCBH=Armyfund.PYCCBH

定义一些局部变量,把select得值赋给句不变量
在饮用局部变量进行比较
JerryOne 2004-04-24
  • 打赏
  • 举报
回复
if 语句不要
begin
...
end
吗?
internetcsdn 2004-04-24
  • 打赏
  • 举报
回复
回复人: hiu9() ( ) 信誉:100 2004-04-24 11:15:00 得分:0


我试后
服务器: 消息 156,级别 15,状态 1,过程 dp_sumarmyfund,行 17
在关键字 'else' 附近有语法错误。
该错误已不存在但出现了下面的错误,这种连接是不是非得需要有主键与外键的关系呢?
我又该怎么去处理呢?麻烦个位高手们再不厌其烦的给解答一下后给分。
列前缀 'personaltable' 与查询中所用的表名或别名不匹配。
服务器: 消息 107,级别 16,状态 1,过程 dp_sumarmyfund,行 12
列前缀 'Armyfund' 与查询中所用的表名或别名不匹配。
服务器: 消息 107,级别 16,状态 1,过程 dp_sumarmyfund,行 12
列前缀 'personaltable' 与查询中所用的表名或别名不匹配。
服务器: 消息 107,级别 16,状态 1,过程 dp_sumarmyfund,行 14
列前缀 'Arrmyfund' 与查询中所用的表名或别名不匹配。
服务器: 消息 107,级别 16,状态 1,过程 dp_sumarmyfund,行 14
列前缀 'Personal' 与查询中所用的表名或别名不匹配。
服务器: 消息 107,级别 16,状态 1,过程 dp_sumarmyfund,行 14
列前缀 'Armyfund' 与查询中所用的表名或别名不匹配。
服务器: 消息 107,级别 16,状态 1,过程 dp_sumarmyfund,行 14
列前缀 'Personaltable' 与查询中所用的表名或别名不匹配。
服务器: 消息 107,级别 16,状态 1,过程 dp_sumarmyfund,行 17
列前缀 'Armyfund' 与查询中所用的表名或别名不匹配。



你试什么代码?
shuichangliu 2004-04-24
  • 打赏
  • 举报
回复
create proc dp_sumarmyfund
@personal nvarchar(255),
@dateyear_1 smalldatetime,
@dateyear_2 smalldatetime,
@sum_12 decimal(6,3)output,
@sumarmy decimal(6,3)output
as
declare @A fieldType,@B fieldType--你自己的类型
declare @C fieldType,@D fieldType
declare @E fieldType,@F fieldType
declare @G fieldType,@H fieldType
declare @I fieldType

select @A=Armyfund.Itemnumber,
@B=Armyfund.Cliquevalue,
@C=Armyfund.Criterion,
@D=Armyfund.PYCCBH,
@E=personaltable.Itemnumber,
@F=Personaltable.countnum,
@G=personaltable.PYCCBH,
@H=personaltable.datayear,
@I=personaltable.Xh
from personaltable,Armyfund
where Personaltable.Itemnumber=Armyfund.Itemnumber
and Personaltable.PYCCBH=Armyfund.PYCCBH
begin
if @E=@A and @I=@personal and @H between @dateyear_1 and @dateyear_2
begin
select @sum_12
end
if @A=@E and @D=@G
begin
select @sumarmy=@sum_12*@C
select @sumarmy
end
else
begin
raiserror('该记录不存在.',16,1)
end
end

34,873

社区成员

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

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