【问题标题】:Issue with returning output from stored procedure从存储过程返回输出的问题
【发布时间】:2013-01-07 12:50:17
【问题描述】:

以下是我的存储过程

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 也有错误的值。问题出在哪里。谢谢你

【问题讨论】:

  • 你要返回的变量是什么?
  • 当你说你在执行语句时得到了正确的值,你能告诉我们你是如何给变量@fromdate@todate赋值的吗?
  • select count() from abc where AppID IN (108,104,113,110,218,171) and Status IN ('T','L') and calldate between '20121201' and '20121231' select count( i>) as decauto from abc where AppID IN (278,283) and Status IN ('T','L') and calldate between '20121201' and '20121231'
  • 当我执行 sp 我确实喜欢 exec [autoivr].[sp_abc] '20120822','20121231'

标签: sql sql-server stored-procedures


【解决方案1】:

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

【讨论】:

  • 你可以在 sp 中看到它是相同的,这就是我执行它的方式 exec [autoivr].[sp_abc] '20120822','20121231'
  • 打印存储过程中每个变量的值并尝试找出哪里出错了,我发现计算中出现了一些问题。
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-07
    • 2019-09-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多