作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试从发票日期中获取会计期间和年份。将 month() 函数与 Case 一起使用,我可以获得时间段。因为第 1 期是在 11 月,所以我需要在这是真的那一年做一个 +1 1
我现在可以将 IF 函数与日期函数一起使用。
我的查询是
Select a.OrderAccount
,a.InvoiceAccount
,a.InvoiceDate
,year(a.InvoiceDate) as Year
,month(a.InvoiceDate) as Month,
Case month(a.InvoiceDate)
WHEN '11' THEN '1' -- increase year by +1
WHEN '12' THEN '2'-- increase year by +1
WHEN '1' THEN '3'
WHEN '2' THEN '4'
WHEN '3' THEN '5'
如有任何建议,我们将不胜感激。谢谢
最佳答案
使用DATEADD
只需在原始日期基础上增加 2 个月:
MONTH(DATEADD(month,2,a.InvoiceDate)) as FiscalMonth,
YEAR(DATEADD(month,2,a.InvoiceDate)) AS FiscalYear,
关于sql - 格式化日期中的 If/Then/Else,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45599964/
我是一名优秀的程序员,十分优秀!