【问题标题】:compare parameter dates with dataset date field in custom code将参数日期与自定义代码中的数据集日期字段进行比较
【发布时间】:2019-09-01 13:23:33
【问题描述】:

我需要创建一个显示净工作日(不包括节假日)的报告。这需要是计算或计算字段。我有自定义代码来计算周末,并且有一个假期数据集,其中包含我需要在其中查找的所有假期。

我在报告中为我的假期日期设置了一个隐藏参数。下面的代码运行,但我得到一个#Error。如您所见,尝试分别提取和比较年、月和日,因为我认为这可能是日期/时间问题。这仍然产生#Error。

函数 NumWorkDays(ByRef startDate As Date, ByRef endDate As Date) as Integer

dim i as integer
dim x as integer
dim totalDays as Integer
dim WeekendDays as Integer
dim HolidayDays as integer
dim sDate as Date
dim numWeekdays as Integer

numWeekdays = 0
WeekendDays = 0
HolidayDays = 0
sDate=startDate

totalDays = DateDiff(DateInterval.Day, startDate , endDate ) + 1

对于 i = 1 到 totalDays

    if DatePart(dateinterval.weekday,sDate ) = 1 then
        WeekendDays = WeekendDays + 1
    end if
    if DatePart(dateinterval.weekday, sDate ) = 7 then
        WeekendDays = WeekendDays + 1
    end if
     sDate = DateAdd("d", 1, sDate )
next i

sDate=开始日期

对于 x = 1 到总天数

    if DatePart(dateinterval.weekday,sDate ) <> 1 or 
         DatePart(dateinterval.weekday,sDate ) <> 7 then
        for i = 1 to Report.Parameters!HolidayParam.Count()
            if Year(Report.Parameters!HolidayParam.Value(i))=Year(sDate) and
               Month(Report.Parameters!HolidayParam.Value(i))=Month(sDate) and 
                Day(Report.Parameters!HolidayParam.Value(i))= Day(sDate) then           
               HolidayDays = HolidayDays + 1
               Exit For                
            End if
         next i
     end if
    sDate = DateAdd("d", 1, sDate )

下一个

numWeekdays  = totalDays - WeekendDays -HolidayDays
return numWeekdays  

结束函数

只是寻找关于我哪里出错的想法!谢谢!

【问题讨论】:

  • 我已经单步执行了代码,它会在 If Year(Report.Parameters...etc...) 产生 #Error 如果我使用 "If Report.Parameters!HolidayParam .Value(i)=sDate then"

标签: date parameters compare ssrs-2012


【解决方案1】:

好的,我知道了。作为 SSRS 的新手,我在无法单步执行自定义代码或设置断点以在出现值时显示值时遇到了困难!这很简单,它需要是一个多值参数。我没有检查它,因为我将它隐藏起来,我并没有觉得它需要它。
我通过在报告标题中放置一个文本框并简单地显示我的参数计数来发现问题。当它显示“1”时,我就知道我遇到了问题!

更新后的代码 sn-p 是(其余的都保持不变):

for i = 0 to Report.Parameters!HolidayParam.Count()-1
    if Report.Parameters!HolidayParam.Value(i))=sDate then         
        HolidayDays = HolidayDays + 1
        Exit For                
     End if
next i

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-18
    • 2016-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多