简体   繁体   English

如何设置自定义SSRS日期参数?

[英]How can I set a custom SSRS date parameter?

I have a series of reports that require date ranges. 我有一系列要求日期范围的报告。 To "help" the customer, we have a dropdown for quick dates (Last 7 days, this month, last month, etc.) One of the dropdown items is "Custom". 为了“帮助”客户,我们提供了一个快捷日期下拉菜单(过去7天,本月,上个月等)。下拉菜单之一是“自定义”。

When the user selects anything other than custom, we use a dataset within the Available Values and Default Values of the StartDate and EndDate parameters to force the correct datestamps, accordingly. 当用户选择自定义以外的任何内容时,我们将在StartDate和EndDate参数的Available Values和Default Values中使用一个数据集来相应地强制正确的日期戳。

However when the user selects "Custom", we want to allow the user to select ANY date in the StartDate and EndDate parameters. 但是,当用户选择“自定义”时,我们希望允许用户在StartDate和EndDate参数中选择ANY日期。 The Available Values for these parameters can then be anything, which can't be done since we have defined a set of Available values. 这些参数的可用值可以是任何值,因为我们定义了一组可用值,所以无法完成。 I tried returning NULL from my stored proc, but that just prevents the user from setting anything. 我尝试从存储的proc返回NULL,但这只是阻止用户设置任何内容。

What's the best way to accomplish this?? 做到这一点的最好方法是什么? This task sounded easy at first, but I'm already about to pull my hair out. 起初,这项任务听起来很轻松,但是我已经准备好了。

UPDATE UPDATE

I have a dropdown, SelectDateRange, where am pulling my options for the date ranges from the following DB Function: 我有一个下拉菜单SelectDateRange,从以下DB函数中提取日期范围的选项:

CREATE FUNCTION [dbo].[ufn_ReportDateRanges]
(
)
RETURNS @Dates TABLE
    (
    DateRangeID   INT,
    DateRangeName VARCHAR(255),
    StartDate     DATE,
    EndDate       DATE
    )
AS
BEGIN

    INSERT INTO @Dates SELECT 1, 'Today',
                  GetDate(), 
                  GetDate()
    INSERT INTO @Dates SELECT 2, 'Previous 7 Days', 
                  GetDate() - 7, 
                  GetDate()
    INSERT INTO @Dates SELECT 3, 'Current Week',
                  DateAdd(dd, -(DatePart(dw, GetDate()) - 1), GetDate()),
                  DateAdd(dd, (7 - DatePart(dw, GetDate())), GetDate())
    INSERT INTO @Dates SELECT 4, 'Previous Week',
                  DateAdd(dd, -(DatePart(dw, GetDate()) - 1) - 7, GetDate()),
                  DateAdd(dd, -(DatePart(dw, GetDate()) - 1) - 1, GetDate())
    INSERT INTO @Dates SELECT 5, 'Current Month',
                  DateAdd(day,-(DatePart(day, getdate()) + 1), GetDate()),
                  DateAdd(month, 1, DateAdd(day, -DatePart(day, GetDate()), GetDate()))
    INSERT INTO @Dates SELECT 6, 'Previous Month',  
                  DateAdd(month, DateDiff(month, 0, GetDate())-1, 0),
                  DateAdd(month, DateDiff(month, -1, GetDate())-1, -1)
    INSERT INTO @Dates SELECT 7, 'Year To Date',  
                  DateAdd(yyyy, DateDiff(yyyy, 0, GetDate()), 0),
                  GetDate()

    INSERT INTO @Dates SELECT 99, 'Custom',  
                  NULL,
                  NULL

    RETURN
END

My dataset, DateRanges, is then: 然后,我的数据集DateRanges是:

SELECT        DateRangeID, DateRangeName, StartDate, EndDate
FROM          dbo.ufn_ReportDateRanges()
WHERE         DateRangeID = @SelectedDateRangeID

In my StartDate and EndDate parameters, I then set Available Values to: 然后,在我的StartDate和EndDate参数中,将Available Values设置为:

Dataset: DateRanges
Value: StartDate (or EndDate, respectively)
Label: StartDate (or EndDate, respectively)

and their Default Values are set to: 并且它们的默认值设置为:

DataSet: DateRanges
Value: StartDate (or EndDate, respectively)

This works GREAT for forcing the fields to always match the dropdown selection. 这非常适用于强制字段始终与下拉选择匹配。 But when the user selects "Custom", I would like to free up the fields to be any date, using the date picker (not a very long dropdown list of all possible dates in all of history). 但是,当用户选择“自定义”时,我想使用日期选择器(不是一个很长的下拉列表,列出所有历史记录中的所有可能的日期)将这些字段释放为任何日期。 Is this even possible??? 这有可能吗???

Update 更新

Option 3 选项3

Set default values to None . 默认值设置为None

When the user selects Last 7 days, Last Month etc in DateRangeParameter. 当用户在DateRangeParameter中选择Last 7 days,Last Month等时。 it doesn't populate startdate and end date. 它不会填充开始日期和结束日期。 You table datasets calculates the startdate and enddate based on the dateRangeId entered by the user. 您的表数据集根据用户输入的dateRangeId计算开始日期和结束日期。

When user picks Custom and enters the startdate and enddate, your table dataset will use the user selected startdate and enddates. 当用户选择“ 自定义”并输入开始日期和结束日期时,表数据集将使用用户选择的开始日期和结束日期。


Option 1 . 选项1 Why do you need available values. 为什么需要可用的值。 I think you should keep it as None . 我认为您应该将其保留为None Only customize the default values tab. 仅自定义默认值选项卡。

Option 2 . 选项2 If option 1 doesn't work try this. 如果选项1不起作用,请尝试此操作。

You would need to update the available value dataset to pull all the dates. 您将需要更新可用值数据集以提取所有日期。

For Startdate try something like this 对于开始日期,尝试这样的事情

WITH CTE as
(
SELECT 'Custom' QuickDateParam, CAST('01/01/1980' as datetime) as D
  UNION ALL
SELECT 'Custom' QuickDateParam, DATEADD(d,1, D)
  FROM CTE
  WHERE D < getDate()
)

SELECT QuickDateParam, D FROM CTE
UNION ALL
SELECT 'Last7Days', DATEADD(d, -7, GETDATE())
UNION ALL
SELECT 'LastMonth', DATEADD(m, -1, GETDATE())
option (maxrecursion 0)

In the dataset for available values pass the QuickDateParam and it will show the corresponding dates. 在可用值的数据集中传递QuickDateParam ,它将显示相应的日期。

Same way you can do for the end date also. 同样,您也可以为结束日期进行操作。

Note : Can you share your datasets and data for Default Values/Available values as that will make it easier to answer your question. 注意 :是否可以共享默认值/可用值的数据集和数据,因为这将使回答问题变得更加容易。

I would edit the dataset providing the Default Values for StartDate and EndDate so that it returns Today's date (eg GETDATE()) or similar for the "Custom" row. 我将编辑为StartDate和EndDate提供默认值的数据集,以便它返回“自定义”行的今天的日期(例如GETDATE())或类似的日期。 Then the user can use the Calendar control to choose whatever dates they want. 然后,用户可以使用“日历”控件选择所需的日期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM