首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

大家帮小弟我看看这个存储过程错哪了呢?该如何修改呢

2012-02-25 
大家帮我看看这个存储过程哪里错了呢?该怎么修改呢?CREATEprocgetInfo@sipvarchar(50),/*传入参数*/@dipva

大家帮我看看这个存储过程哪里错了呢?该怎么修改呢?
CREATE   proc   getInfo
@sip   varchar(50),   /*传入参数*/
@dip   varchar(50),   /*传入参数*/
@Zgjcs   int   output,
@Zbgjcs   int   output,
@Gjcs   int   output,
@Zfsbs   int   output,
@Zfssjl   int   output,
@Zjsbs   int   output,
@Zjssjl   int   output,
@Fsbs   int   output,
@Fssjl   int   output
as
begin
    @Zgjcs   =   select   (select   count(*)   from   Program1   where     sip=@sip   )   +   (select   count(*)     from   Program2   where     sip=@sip);
    @Zbgjcs   =   select   (select   count(*)     from   Program1   where     dip=@dip)   +   (select   count(*)     from   Program2   where     dip=@dip);
    @Gjcs   =   select   (select   count(*)   from   Program1   where     sip=@sip   and   dip=@dip)   +     (select   count(*)     from   Program2   where     sip=@sip   and   dip=@dip);
    select   @Zfsbs   =   (sum(a.trigger_times)+sum(b.repeat)),   @Zfssjl   =   sum(b.traffic)   from   Program1   a,   Program2   b   where   a.sip=@sip   or   b.sip=@sip;
    select   @Zjsbs   =   (sum(a.trigger_times)+sum(b.repeat)),   @Zjssjl   =   sum(b.traffic)   from   Program1   a,   Program2   b   where   a.dip=@dip   or   b.dip=@dip;
    select   @Fsbs   =     (sum(a.trigger_times)+sum(b.repeat)),     @Fssjl   =   sum(b.traffic)     from   Program1   a,   Program2   b   where   (a.sip=@sip   and   a.dip=@dip)   or   (b.sip=@sip   and   b.dip=@dip);
end
GO

[解决办法]
@Zgjcs = select (select count(*) from Program1 where sip=@sip ) + (select count(*) from Program2 where sip=@sip);

是不是应该是

select @Zgjcs=(select count(*) from Program1 where sip=@sip ) + (select count(*) from Program2 where sip=@sip);
[解决办法]
CREATE proc getInfo
@sip varchar(50), /*传入参数*/
@dip varchar(50), /*传入参数*/
@Zgjcs int output,
@Zbgjcs int output,
@Gjcs int output,
@Zfsbs int output,
@Zfssjl int output,
@Zjsbs int output,
@Zjssjl int output,
@Fsbs int output,
@Fssjl int output
as
begin
set @Zgjcs = (select count(*) from Program1 where sip=@sip ) + (select count(*) from Program2 where sip=@sip)
set @Zbgjcs = (select count(*) from Program1 where dip=@dip) + (select count(*) from Program2 where dip=@dip)
set @Gjcs = (select count(*) from Program1 where sip=@sip and dip=@dip) + (select count(*) from Program2 where sip=@sip and dip=@dip)
select @Zfsbs = (sum(a.trigger_times)+sum(b.repeat)), @Zfssjl = sum(b.traffic) from Program1 a, Program2 b where a.sip=@sip or b.sip=@sip
select @Zjsbs = (sum(a.trigger_times)+sum(b.repeat)), @Zjssjl = sum(b.traffic) from Program1 a, Program2 b where a.dip=@dip or b.dip=@dip
select @Fsbs = (sum(a.trigger_times)+sum(b.repeat)), @Fssjl = sum(b.traffic) from Program1 a, Program2 b where (a.sip=@sip and a.dip=@dip) or (b.sip=@sip and b.dip=@dip)
end
GO
这样试试

热点排行