使用Teradata 15.1x
我试图选择上一个工作日的数据。我可以使用
前一天cast(cast(cast(a.date_dim_ck as varchar(13)) as date format 'yyyymmdd') as date format 'mm-dd-yyyy') = current_date - 1
但是当我尝试做一个案例,在周一回顾3天而不是1时(为了得到星期五的数据,见下文),我得到了#34; [3707]语法错误,预期的东西喜欢' END'之间的关键字')'和' ='。"
where case
when td_day_of_week(current_date)<>2
then
cast(cast(cast(a.date_dim_ck as varchar(13)) as date format 'yyyymmdd') as date format 'mm-dd-yyyy') = current_date - 1
else
cast(cast(cast(a.date_dim_ck as varchar(13)) as date format 'yyyymmdd') as date format 'mm-dd-yyyy') = current_date - 3
我做错了什么?
答案 0 :(得分:0)
您只能使用案例陈述根据其他条件确定字段的值。请参阅以下语法。
where cast(cast(cast(a.date_dim_ck as varchar(13)) as date format 'yyyymmdd') as date format 'mm-dd-yyyy') = case
when td_day_of_week(current_date)<>2
then
current_date - 1
else
current_date - 3
end