将函数值传递给SSRS中的存储过程

时间:2017-06-14 04:41:14

标签: function datetime stored-procedures sql-server-2014 ssrs-2012

我有一个计算时差的函数,不包括周末,我已经创建了一个存储过程来调用该函数。当我测试sp时,只显示了消息部分,我是新的,不确定这是否正确。我无法将参数传递给SSRS。请多多帮助,谢谢。

Alter Proc Test_1 
@DownTime datetime,
@Uptime   datetime =null  --since there are some null value in uptime column
AS  
Begin

print 'enter'

declare @duration int 
select  @duration = [dbo].[CalcWorkMinutes](@DownTime,@Uptime)
print 'abc'

;with cte_test2
as (
SELECT DownTime
,UpTime
,datediff(hh,DownTime,UpTime)  AS duration
FROM Test
)

select DownTime,UpTime,duration from cte_test2

where  DownTime = @DownTime and UpTime=@UpTime 
and duration=@duration
--print 'pass'

print 'duration'+' '+convert(varchar,@duration)
RETURN 

END 
 --execute [dbo].[test_1] @downtime ='2017-06-02 09:00:00.000', @Uptime ='2017-06-05 09:00:00.000' 

1 个答案:

答案 0 :(得分:1)

嗯......这个有很多事情要发生。看起来您正试图查看在某个时间段内有人会传入的停机时间是什么样的?如果是这种情况,我会将参数更改为:StartDate和EndDate。你真的不需要CTE来应用这些参数......下面的代码......我只是在这里猜测:

    Alter Proc Test_1 
@startdate datetime,
@enddate   datetime   --since there are some null value in uptime column
AS  
Begin

print 'enter'



SELECT 
    DownTime
    ,UpTime
    ,[dbo].[CalcWorkMinutes](DownTime,UpTime)  AS duration
FROM Test as a
where 
    downtime >= @startdate
    and b.downtime < dateadd(day,1,@enddate) 


RETURN 

END