【问题标题】:Month End Data for SSRS ReportSSRS 报告的月末数据
【发布时间】:2018-06-20 19:37:34
【问题描述】:

我正在尝试构建从共享数据源调用数据的 SSRS 报告。我需要建立一个包含多个字段的表:

贷款编号、借款人姓名、今日余额、月末余额

我创建了两个冗余的数据源;一个用于报告运行的日期(今天的余额),另一个用于获取过去某个日期的数据(余额月末)。

在 Python 中,我可以使用以下逻辑根据 elif 设置一个变量来获取上个月末(不能是假期或周末):

import datetime

today = datetime.date(2018, 6, 19)
monthend = datetime.date(2018, 12, 14)

if today >= datetime.date(2018, 6, 1) and today < datetime.date(2018, 6, 30):
    monthend = datetime.date(2018, 5, 31)
    print(monthend)
elif today >= datetime.date(2018, 7, 1) and today < datetime.date(2018, 7, 31):
    monthend = datetime.date(2018, 6, 29)
    print(monthend)
elif today >= datetime.date(2018, 8, 1) and today < datetime.date(2018, 8, 31):
    monthend = datetime.date(2018, 7, 31)
    print(monthend)
elif today >= datetime.date(2018, 9, 1) and today < datetime.date(2018, 9, 30):
    monthend = datetime.date(2018, 8, 31)
    print(monthend)
elif today >= datetime.date(2018, 10, 1) and today < datetime.date(2018,
                           10, 31):
    monthend = datetime.date(2018, 9, 28)
    print(monthend)
elif today >= datetime.date(2018, 11, 1) and today < datetime.date(2018,
                           11, 30):
    monthend = datetime.date(2018, 10, 31)
    print(monthend)
elif today >= datetime.date(2018, 12, 1) and today < datetime.date(2018,
                           12, 31):
    monthend = datetime.date(2018, 11, 30)
    print(monthend)
elif today >= datetime.date(2019, 1, 1) and today < datetime.date(2019,
                           1, 31):
    monthend = datetime.date(2018, 12, 31)
    print(monthend)

如何在报表端或数据库端编写此逻辑以获取上个月结束日期参数?

谢谢

【问题讨论】:

  • 在 SQL Server 中,使用 EOMONTH() 和 DATEADD() 来获取您之前的月份范围或日期。我敢肯定,当您搜索“SQL Server 上个月结束日期”时会出现这种情况。

标签: python sql date reporting-services sql-server-2016


【解决方案1】:

这也可以:

DECLARE @today DATETIME = CONVERT(CHAR(8), GETDATE(), 112) 
SELECT DATEADD(DAY, - DAY(@Today), @Today) [Last Day of Last Month]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 2014-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多