if 语句不要
begin
...
end
吗?

解决方案 »

  1.   

    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得值赋给句不变量
    在饮用局部变量进行比较
      

  2.   

    select @sumarmy=@sum_12*Armyfund.Criterion
    select @sumarmy应该改为
    begin
     select @sumarmy=@sum_12*Armyfund.Criterion
     select @sumarmy
    end
      

  3.   

    养成良好的习惯,IF后面不管有几句话
    最好一律加上begin end
    这样肯定没错
      

  4.   

    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
      

  5.   

    我试后
    服务器: 消息 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' 与查询中所用的表名或别名不匹配。
      

  6.   

    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 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
      

  7.   

    回复人: 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' 与查询中所用的表名或别名不匹配。 
     
    你试什么代码?
      

  8.   

    试如下代码:表已在库中存在
    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