从存储过程返回输出的问题

时间:2013-01-07 12:50:17

标签: sql sql-server stored-procedures

以下是我的存储过程

ALTER PROCEDURE [aaa].[sp_getabc] (                
      @fromdate smalldatetime,                
@todate smalldatetime)                


AS                
BEGIN                
SET NOCOUNT ON;                


declare @tmp1 as int  
declare @tmp2 as int  
declare @sum as int  
declare @tmp3 as int  
select @tmp1 = (select count(*) as decdbo from abc where AppID IN (108,104,113,110,218,171) and Status IN ('T','L') and calldate between  @fromdate and  @todate)  
select @tmp2 = (select count(*) as decauto from abc where AppID IN (278,283) and Status IN ('T','L') and calldate between  @fromdate and  @todate)  

select @sum = @tmp1 + @tmp2  

select @tmp3 = (select SUM(Duration)/60 as DecemberLastWeek from abc where dnis = '6503533019' and calldate between  @fromdate and  @todate)  

select @tmp3 as Duration , @sum as Transcriptions , @sum/@tmp3 as TransPerMin   


END

当我执行语句而不是存储过程时,我得到正确的值,而当我运行存储过程时,我在@ tmp3和@ sum / @ tmp3中得不到任何NULL,而@sum也有错误的值。问题在哪里。谢谢

2 个答案:

答案 0 :(得分:0)

检查@fromdate@todate变量,两种情况必须不同(即格式)

答案 1 :(得分:0)

解决了问题是我的存储过程是在autoivr中,但我想要访问的表是在dbo中,我没有用表名写dbo。