我试图返回一个依赖于current_date的日期范围。其逻辑如下:
如果当前月份是1月,则返回前一年的开始;否则返回当前年度的开始。
附加的代码不断抛出语法错误。我在Alteryx中使用NS 64位ODBC来获取信息。
代码:
and t.TRANDATE between
--period beg
(case
when to_char(current_date, 'MM')='01' then add_months(trunc(current_date, 'YYYY'),-12)
else trunc(current_date, 'YYYY')
end)
and
--period end
trunc(current_date,'MM')-1/84600)对于如何清除语法错误或重新构造语句有任何建议吗?
发布于 2022-04-28 20:06:02
您可以使用:
AND t.TRANDATE >= TRUNC(ADD_MONTHS(current_date, -1), 'YYYY')
AND t.TRANDATE < TRUNC(current_date,'MM')发布于 2022-04-28 19:13:54
语法错误?哪个语法错误?我一点也不明白:
SQL> select *
2 from dual
3 where sysdate not between
4 case when to_char(current_date, 'mm') = '01' then add_months(trunc(current_date, 'YYYY'),-12)
5 else trunc(current_date, 'yyyy')
6 end
7 and trunc(current_date, 'mm') - 1/84600;
D
-
X
SQL>(我使用NOT BETWEEN和DUAL表,因为我没有您的表,只是为了证明这段代码工作正常)。
https://stackoverflow.com/questions/72049025
复制相似问题