SSRS 表达式未正确地将 18 个月添加到日期

问题描述 投票:0回答:1

在我的一份报告中,我有这个查询表达式。

=iif(isdate(Fields!Date_of_Funding_Approval.Value),iif(isdate(Fields!Extension_Expiration_Date.Value),Fields!Extension_Expiration_Date.Value,DateAdd("m",18,Fields!Date_of_Funding_Approval.Value)),"")

Date_of_Funding_Approval 是有效日期 = 04/24/2019

Extension_Expiration_Date 为空

因此,我尝试在 Date_of_Funding_Approval 中添加 18 个月,这应该等于 10/24/2020,但它返回的是 04/24/2025。

更新

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Master Table](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [New Project ID#] [nvarchar](255) NULL,
    [District Name] [nvarchar](255) NULL,
    [Program] [nvarchar](50) NULL,
    [School Name] [nvarchar](255) NULL,
    [Project Description] [nvarchar](255) NULL,
    [Qualifying Project Costs] [money] NULL,
    [Wealth Index] [float] NULL,
    [State Financial Participation] [money] NULL,
    [Notes] [nvarchar](max) NULL,
    [Means Value] [float] NULL,
    [Division Reviewed Project Size/POR] [int] NULL,
    [Primary Category] [nvarchar](50) NULL,
    [Secondary Category] [nvarchar](50) NULL,
    [Means Cost Center] [nvarchar](150) NULL,
    [Rescinded] [nvarchar](150) NULL,
    [Final] [nvarchar](150) NULL,
    [Green Incentive SFP] [money] NULL,
    [Date Printed] [datetime] NULL,
    [Manager Area] [nvarchar](255) NULL,
    [Grand Total SFP] [money] NULL,
    [Last_Updated] [datetime] NULL,
    [Extension Expiration Date] [datetime] NULL,
    [Extension Granted] [bit] NOT NULL,
    [Date of Funding Approval] [datetime] NULL,
    [Project Year] [nvarchar](255) NULL,
    [Final Cost SFP of Project] [money] NULL,
    [Project Shown in CMMS] [bit] NOT NULL,
    [Final Pay Inspection Name] [nvarchar](255) NULL,
    [Final Pay Inspection Date] [datetime] NULL,
    [Date Entered] [datetime] NULL,
    [Date Inspected] [datetime] NULL,
    [Percent Complete] [int] NULL,
    [Manager Name] [nvarchar](255) NULL,
    [Date of Report] [datetime] NULL,
    [Additional Notes] [ntext] NULL,
    [LEA] [int] NULL,
    [Stat Financial Participation Notes] [ntext] NULL,
    [username] [nvarchar](50) NULL,
    [conflict_timestamp] [timestamp] NULL,
 CONSTRAINT [PK_Master_Table] PRIMARY KEY CLUSTERED 
(
    [ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[Master Table] ON 
GO
INSERT [dbo].[Master Table] ([ID], [New Project ID#], [District Name], [Program], [School Name], [Project Description], [Qualifying Project Costs], [Wealth Index], [State Financial Participation], [Notes], [Means Value], [Division Reviewed Project Size/POR], [Primary Category], [Secondary Category], [Means Cost Center], [Rescinded], [Final], [Green Incentive SFP], [Date Printed], [Manager Area], [Grand Total SFP], [Last_Updated], [Extension Expiration Date], [Extension Granted], [Date of Funding Approval], [Project Year], [Final Cost SFP of Project], [Project Shown in CMMS], [Final Pay Inspection Name], [Final Pay Inspection Date], [Date Entered], [Date Inspected], [Percent Complete], [Manager Name], [Date of Report], [Additional Notes], [LEA], [Stat Financial Participation Notes], [username]) VALUES (3350, N'xxx-7207-010', N'xxx School District', N'xxx Partnership', N'-Not Specified-', N'xxx - Additions and Conversions', 7022599.0800, 0.43051886092115882, 3999237.7234, NULL, 153.58, 45726, N'Space', N'Conversion + Addition', N'xxx', NULL, NULL, NULL, CAST(N'2022-02-16T07:36:47.000' AS DateTime), N'1', 3999237.7234, CAST(N'2022-02-16T07:36:47.000' AS DateTime), NULL, 0, CAST(N'2019-04-24T00:00:00.000' AS DateTime), N'Year 1', NULL, 0, NULL, NULL, CAST(N'2019-04-29T00:00:00.000' AS DateTime), NULL, NULL, NULL, NULL, NULL, 7207, NULL, NULL)
GO
SET IDENTITY_INSERT [dbo].[Master Table] OFF
GO
ALTER TABLE [dbo].[Master Table] ADD  CONSTRAINT [DF__Master Ta__Means__38845C1C]  DEFAULT ((0)) FOR [Means Value]
GO
ALTER TABLE [dbo].[Master Table] ADD  CONSTRAINT [DF__Master Ta__Divis__39788055]  DEFAULT ((0)) FOR [Division Reviewed Project Size/POR]
GO
ALTER TABLE [dbo].[Master Table] ADD  CONSTRAINT [DF__Master Ta__Green__3A6CA48E]  DEFAULT ((0)) FOR [Green Incentive SFP]
GO
ALTER TABLE [dbo].[Master Table] ADD  CONSTRAINT [DF__Master Ta__Exten__3B60C8C7]  DEFAULT ((0)) FOR [Extension Granted]
GO
ALTER TABLE [dbo].[Master Table] ADD  CONSTRAINT [DF__Master Ta__Proje__3C54ED00]  DEFAULT ((0)) FOR [Project Shown in CMMS]
GO
sql-server reporting-services expression sql-date-functions ssrs-2019
1个回答
1
投票

尝试在查询中使用

DateSerial
添加 18 个月,而不是
DateAdd

在问题中查询实际上没有什么不同,除了使用

DataSerial
,它允许明确指定年、月和日部分。

所以改变后的表达式将是:

=iif(
  IsDate(Fields!Date_of_Funding_Approval.Value),
  iif(
    IsDate(Fields!Extension_Expiration_Date.Value),
    Fields!Extension_Expiration_Date.Value,
    DateSerial(
      Year(Fields!Date_of_Funding_Approval.Value),
      Month(Fields!Date_of_Funding_Approval.Value) + 18,
      Day(Fields!Date_of_Funding_Approval.Value)
    )
  ),
  ""
)
© www.soinside.com 2019 - 2024. All rights reserved.