tsql - TSQL 显示下一个财政年度后的 4 月 1 日
问题描述
我在下面的查询中需要在下一个财政年度之前返回 7 月 1 日,然后在下一个财政年度之后返回到 4 月 1 日。即使在下一个财政年度之后,以下查询也会在 2019 年 7 月 1 日继续返回。
select (case when getdate() < '2020-03-31' then '2019-07-01'
when GETDATE() > '2020-03-31' then
dateadd(month, 3, dateadd(year, datepart(year, dateadd(month, -3, '2021-05-26')) - 1900, 0)) end)
任何帮助表示赞赏
解决方案
这是因为在您when
使用的条件下,getDate()
它总是返回今天的日期。
尝试将其作为参数传递:
Declare @Date date
SET @Date = '2021-05-26'
select (case when @Date < '2020-03-31' then '2019-07-01'
when @Date > '2020-03-31' then
dateadd(month, 3, dateadd(year, datepart(year, dateadd(month, -3, @Date)) - 1900, 0)) end)
推荐阅读
- c# - 避免 ElasticSearch 错误 503 服务器不可用:使用 WaitForStatus
- c# - XNA 4.0 OutOfMemory 异常 spriteBatch
- python - 如何从 SQL Server 获取日期和时间到 python?
- java - 无法将 UTC 转换为本地时间
- rest - HttpClient 无法从运行超过一小时的 rest api 获得任何响应
- javascript - 将参数从一个文件的应用程序获取功能传递到另一个文件
- android - 如何在 Kotlin 中设置 ViewDragHelper 灵敏度?
- python - 如何正确使用 tf.function 与 TensorFlow 数据集
- excel - Range.Calculate 不更新范围内的值
- python-3.x - python:获取pandas计算列中常见模式的出现