带有参数@startdate的SSR

发布于 2025-02-06 07:34:18 字数 786 浏览 3 评论 0 原文

我目前有一个SSRS报告,该报告每天使用以下SQL代码运行。但是,当复制下降而我们错过了一天时,我们的法院人士希望能够通过进入日期1来手动运行丢失的日期。

我需要一些帮助来设置参数@StartDate,该参数将在下面运行代码。

我有此SQL:

Select *

from Court

WHERE

case_filed_dt =  
CASE WHEN datepart(weekday,getdate())= 2 THEN  
   datediff(day,3,getdate())
  ELSE
   datediff(day,1,getdate()) 
  END

Order by court asc

简单的案例语句,查看报告的日期运行的日期,如果它在周一运行,则可以在星期五的数据中获取前一天的数据。

我想为我的“ case_filed_dt”字段添加一个参数@startdate,以便手动运行,以防遗漏报告。

示例:

如果我为@startdate = '06 -06-2022'运行,它将像我的案例语句代码一样执行,并获取'06 -03-2022'的数据。如果我为@StartDate = '06 -07-2022'运行,数据将用于6-06-2022'。

谢谢, 杰

I currently have an SSRS report that runs daily with the below SQL code as it should. But, when replication goes down and we miss a day, our Court people would like to be able to manually run a missed date by entering a date #1.

I need some help with setting up the parameter @StartDate, that will run the code below.

enter image description here

I have this SQL:

Select *

from Court

WHERE

case_filed_dt =  
CASE WHEN datepart(weekday,getdate())= 2 THEN  
   datediff(day,3,getdate())
  ELSE
   datediff(day,1,getdate()) 
  END

Order by court asc

Simple case statement that looks at the date the report is run, if it runs on Monday's, it get Friday's data otherwise previous day's data.

I would like to add a parameter @startdate for my "case_filed_dt" field, to run manually, in case a report is missed.

Example:

If I run for @startdate = '06-06-2022' it will do as my case statement code does, and get data for '06-03-2022'. If I run for @startdate ='06-07-2022', data is for 6-06-2022'.

Thanks,
jer

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愁以何悠 2025-02-13 07:34:18

我会保持这个简单。

更改您现有的数据集查询以接受类似的参数( pstartdate )。

Select *
from Court
WHERE
case_filed_dt =  
CASE WHEN datepart(weekday, @pStartDate)= 2 THEN  
   datediff(day,3, @pStartDate)
  ELSE
   datediff(day,1, @pStartDate) 
  END
Order by court asc

然后,在您的报告中,将参数的默认值设置为表达式为一个

=Today()

表达式它将使用 today()作为开始日期,或者如果报告手动运行,则可以由用户选择任何日期。

I would keep this simple.

Change your existing dataset query to accept a parameter (pStartDate) like this..

Select *
from Court
WHERE
case_filed_dt =  
CASE WHEN datepart(weekday, @pStartDate)= 2 THEN  
   datediff(day,3, @pStartDate)
  ELSE
   datediff(day,1, @pStartDate) 
  END
Order by court asc

Then in your report, set the parameter's default value to be an expression

=Today()

Then if the report is run as normal with no parameters passed, it will use Today() as the start date or if the report is run manually, any date can be selected by the user.

澜川若宁 2025-02-13 07:34:18

小提琴上的一些版本应该可以让您开始,该版本使用一个变量来模拟案例语句的效果。
更改日期,然后查看发生的情况

Declare @DateNow datetime = '2022-06-03'
SELECT @DateNow as YourDate, DATENAME(WEEKDAY, @DateNow) AS DayNow, '',
CASE 
WHEN DATENAME(WEEKDAY, @DateNow) = 'Monday' THEN 
   DateAdd(day,-3,@DateNow)
   ELSE
     DateAdd(day,-1,@DateNow)
    END AS ReportDate

a few versions on the fiddle, which should get you started, this one using a variable to simulate the effects of the Case statement.
Change the date and see what happens

Declare @DateNow datetime = '2022-06-03'
SELECT @DateNow as YourDate, DATENAME(WEEKDAY, @DateNow) AS DayNow, '',
CASE 
WHEN DATENAME(WEEKDAY, @DateNow) = 'Monday' THEN 
   DateAdd(day,-3,@DateNow)
   ELSE
     DateAdd(day,-1,@DateNow)
    END AS ReportDate

https://dbfiddle.uk/?rdbms=sqlserver_2017&fiddle=b3ae703d3be9ace930822f7e20230018

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文