从 SQL 存储过程返回薪资日期表

发布于 2024-09-28 23:08:57 字数 476 浏览 4 评论 0原文

我正在使用 SQL Server Reporting Services 2008,这对我来说有点新,因为我的大部分经验都是 LAMP 开发。此外,将大部分逻辑作为存储过程转移到 SQL 中是我不太熟悉但愿意做的事情。任何帮助或指导将不胜感激。

我需要以表格形式列出可接受的工资单日期,以用作报告参数的允许值。理想情况下,该人员将能够从报告参数提供的下拉列表中选择此工资单日期,然后在数据集中使用该日期从表中提取数据。如果可能的话,我希望将逻辑存储在 SQL 服务器上,因为这很可能会在其他一些报告中使用。

创建日期列表的逻辑相当简单。它从系统所需的最早的工资单日期(2007 年的某个时间)开始,然后每两周更新一次。该过程或函数应返回一个表,其中包含所有这些日期(包括最近的即将到来的工资单日期)。

在我看来,解决这个问题的方法是创建一个临时表,向其中添加日期列表,然后返回该表以便报告参数可以读取它的过程或函数。这是一种可以接受的方式吗?

任何想法、例子或想法将不胜感激。

I'm working with SQL Server Reporting Services 2008, which is somewhat new to me, as most of my experience is with LAMP development. In addition, moving most of the logic to SQL as stored procedures is something I'm not very familiar with, but would like to do. Any help or direction would be greatly appreciated.

I need a list of acceptable payroll dates in the form of a table to use as the allowed values for a report parameter. Ideally, the person will be able to select this payroll date from the drop-down provided by the report parameter, which will then be used in the dataset to pull data from a table. I would like the logic to be stored on the SQL server if possible, as this is something that will most likely be used on a few other reports.

The logic to create the list of dates is rather simple. It starts with the oldest payroll date that is need by the system (sometime in 2007) and simply goes every two weeks from there. The procedure or function should return a table that contains all these dates up to and including the nearest upcoming payroll date.

It seems to me that the way to go about this would be a procedure or function that creates a temporary table, adds to it the list of dates, and then returns this table so that the report parameter can read it. Is this an acceptable way to go about it?

Any ideas, examples, or thoughts would be greatly appreciated.

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

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

发布评论

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

评论(2

娜些时光,永不杰束 2024-10-05 23:08:57

我会使用类似这样的 CTE:

;WITH PayPeriod AS (
    SELECT @DateIn2007 AS p UNION ALL
    SELECT DATEADD(dd, 14, p) as P FROM PayPeriod WHERE p < GetDate() )
SELECT p FROM PayPeriod
OPTION ( MAXRECURSION 500 )

MAXRECURSION 和/或 where 参数限制它将生成的日期数量。

当然,您可以使用参数来计算出正确的限制,以获得正确的最后日期。

I would use a CTE something like this one:

;WITH PayPeriod AS (
    SELECT @DateIn2007 AS p UNION ALL
    SELECT DATEADD(dd, 14, p) as P FROM PayPeriod WHERE p < GetDate() )
SELECT p FROM PayPeriod
OPTION ( MAXRECURSION 500 )

The MAXRECURSION and/or where parameter limits the number of dates it will generate.

You can use a parameter to figure out the correct limit to get the correct last date still, of course.

暮光沉寂 2024-10-05 23:08:57

尝试这样的事情:

;with AllDates AS
(
    SELECT CONVERT(datetime,'1/1/2007') AS DateOf
    UNION ALL
    SELECT DateOf+14
        FROM AllDates
    WHERE DateOf<GETDATE()+14
)
SELECT * FROM AllDates
OPTION (MAXRECURSION 500)

您可以将其放入视图或函数中。

但是,我建议不要显示包含这么多值的选择框,为什么不只提供两个文本框字段:开始日期结束日期,并将它们默认为合理的值值,只是我的 2 美分

try something like this:

;with AllDates AS
(
    SELECT CONVERT(datetime,'1/1/2007') AS DateOf
    UNION ALL
    SELECT DateOf+14
        FROM AllDates
    WHERE DateOf<GETDATE()+14
)
SELECT * FROM AllDates
OPTION (MAXRECURSION 500)

you can put this in a view or function.

However, I would suggest that instead of presenting a select box of this many values, why not just have two text box fields: start date and end date and default them to reasonable values, just my 2 cents

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