if 语句不要
begin
...
end
吗?
begin
...
end
吗?
解决方案 »
- 简单的sql问题
- NVarcahr的困惑。。。
- 很简单的sql更新语句,本人新手,请指教
- MSSQL 如何修复 表
- SQLserver text字段存储空间问题
- 一个SQL插入问题
- 一个简单的问题?
- 使用何种软件可以查看Sql Server 2k的日志文件.ldf的对表的具体操作日志?
- 求助:如何实现Sql Server 导出数据时带上字段列名,通过脚本实现? 急急急急!
- 散分!!!怎么样让一个字段No(Int)的值从X递增到X+N.也就是说第一条记录字段No值为50,下一条记录的字段No值则为51,再下一条则为52,一直如
- Recordcount为什么不能取得记录数呢?
- 新手请教:求个 trigger!谢了。
from personaltable,Armyfund
where Personaltable.Itemnumber=Armyfund.Itemnumber and Personaltable.PYCCBH=Armyfund.PYCCBH定义一些局部变量,把select得值赋给句不变量
在饮用局部变量进行比较
select @sumarmy应该改为
begin
select @sumarmy=@sum_12*Armyfund.Criterion
select @sumarmy
end
最好一律加上begin end
这样肯定没错
@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
服务器: 消息 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' 与查询中所用的表名或别名不匹配。
@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 fieldTypeselect @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
我试后
服务器: 消息 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' 与查询中所用的表名或别名不匹配。
你试什么代码?
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