One month limit - Reporting Service

試著忘記壹切 提交于 2019-12-11 04:57:30

问题


I am building a report in Micrososft SQL Reporting Services and, I have two date fields, startDate and endDate.

I need to limit the date range, at least in thirty days (or a month). For example, if startDate is 2012/01/01 and endDate is 2012/02/02, it should raise an error message, otherwise (being less than thirty days of difference), it can continue. How can I do that in reporting service?


回答1:


You can use a data set to provide default values for your endDate parameter based on your startDate parameter.

Add a Dataset named DefaultStartDate. Set query text to:

select DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0) as [startDate];

Add a Parameter named startDate. Set type to Date/Time and get the default value from the DefaultStartDate query:

Add a Dataset named ValidEndDates. Set query text to something like the following, to generate a list of valid end dates based on the start date:

with A as
( select 1 as i UNION ALL select i+1 from A where i<30 )
select DATEADD(dd, i, @startDate) as [endDate] from A;

Add a Parameter named endDate. Set type to Date/Time and get the available values from the ValidEndDates Dataset:




回答2:


This is an old question, but there is an answer. A high-level explanation of the solution is to write code in the Report Properties, add a hidden parameter that contains code to validate the parameters, and a conditional expression in the DataSet. Please see the following link for a detailed explanation: https://gugiaji.wordpress.com/2012/03/26/easy-step-by-step-ssrs-parameter-validation-using-code



来源:https://stackoverflow.com/questions/11294570/one-month-limit-reporting-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!