为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
【DM版本】:8
【操作系统】:windows10
【CPU】:
【问题描述】:between附近报错,怀疑是case when 或者是字符串转时间格式出问题:select
count()
from ciip.ads_blood_discard_record a
where
a.blood_discard_main_reason_code in ('4100217120327000048','4100217120327000049','4100217120327000050',
'4100217120510000000','4100217120510000001','4100217120510000002','4100217120327000055','4100217120510000003',
'4100217120327000043','610021718342000002','910021722281000000','910021722281000001','910021722362000000')
and a.apply_department ='05' and a.ciip_delete = '0'
and case when '01' = '01' then a.blood_discard_date between to_timestamp(concat('2024', '-12-26 00:00:00'), 'YYYY-MM-DD HH24:MI:SS')
and to_timestamp(concat('2024-', '01-25 23:59:59'), 'YYYY-MM-DD HH24:MI:SS')
when '01' = '02' then a.blood_discard_date between to_timestamp(concat('2024', '-', '01-26 00:00:00'), 'YYYY-MM-DD HH24:MI:SS')
and to_timestamp(concat('2024', '-', '02-25 23:59:59'), 'YYYY-MM-DD HH24:MI:SS')
when '01' = '03' then a.blood_discard_date between to_timestamp(concat('2024', '-', '02-26 00:00:00'), 'YYYY-MM-DD HH24:MI:SS')
and to_timestamp(concat('2024', '-', '03-25 23:59:59'), 'YYYY-MM-DD HH24:MI:SS')
when '01' = '04' then a.blood_discard_date between to_timestamp(concat('2024', '-', '03-26 00:00:00'), 'YYYY-MM-DD HH24:MI:SS')
and to_timestamp(concat('2024', '-', '04-25 23:59:59'), 'YYYY-MM-DD HH24:MI:SS')
when '01' = '05' then a.blood_discard_date between to_timestamp(concat('2024', '-', '04-26 00:00:00'), 'YYYY-MM-DD HH24:MI:SS')
and to_timestamp(concat('2024', '-', '05-25 23:59:59'), 'YYYY-MM-DD HH24:MI:SS')
when '01' = '06' then a.blood_discard_date between to_timestamp(concat('2024', '-', '05-26 00:00:00'), 'YYYY-MM-DD HH24:MI:SS')
and to_timestamp(concat('2024', '-', '06-25 23:59:59'), 'YYYY-MM-DD HH24:MI:SS')
when '01' = '07' then a.blood_discard_date between to_timestamp(concat('2024', '-', '06-26 00:00:00'), 'YYYY-MM-DD HH24:MI:SS')
and to_timestamp(concat('2024', '-', '07-25 23:59:59'), 'YYYY-MM-DD HH24:MI:SS')
when '01' = '08' then a.blood_discard_date between to_timestamp(concat('2024', '-', '07-26 00:00:00'), 'YYYY-MM-DD HH24:MI:SS')
and to_timestamp(concat('2024', '-', '08-25 23:59:59'), 'YYYY-MM-DD HH24:MI:SS')
when '01' = '09' then a.blood_discard_date between to_timestamp(concat('2024', '-', '08-26 00:00:00'), 'YYYY-MM-DD HH24:MI:SS')
and to_timestamp(concat('2024', '-', '09-25 23:59:59'), 'YYYY-MM-DD HH24:MI:SS')
when '01' = '10' then a.blood_discard_date between to_timestamp(concat('2024', '-', '09-26 00:00:00'), 'YYYY-MM-DD HH24:MI:SS')
and to_timestamp(concat('2024', '-', '10-25 23:59:59'), 'YYYY-MM-DD HH24:MI:SS')
when '01' = '11' then a.blood_discard_date between to_timestamp(concat('2024', '-', '10-26 00:00:00'), 'YYYY-MM-DD HH24:MI:SS')
and to_timestamp(concat('2024', '-', '11-25 23:59:59'), 'YYYY-MM-DD HH24:MI:SS')
when '01' = '12' then a.blood_discard_date between to_timestamp(concat('2024', '-', '11-26 00:00:00'), 'YYYY-MM-DD HH24:MI:SS')
and to_timestamp(concat('2024', '-', '12-25 23:59:59'), 'YYYY-MM-DD HH24:MI:SS')
when '01' = '上半年' then to_timestamp(concat(a.blood_discard_date), 'YYYY-MM-DD HH24:MI:SS' )>= to_timestamp(concat('2024'-1, '-12-26'), 'YYYY-MM-DD HH24:MI:SS')
and to_timestamp(concat(a.blood_discard_date), 'YYYY-MM-DD HH24:MI:SS') <= to_timestamp(concat('2024', '-06-25 23:59:59'), 'YYYY-MM-DD HH24:MI:SS ')
when '01' = '下半年' then to_timestamp(concat(a.blood_discard_date), 'YYYY-MM-DD HH24:MI:SS') >= to_timestamp(concat('2024', '-06-26 '), 'YYYY-MM-DD HH24:MI:SS ')
and to_timestamp(concat(a.blood_discard_date), 'YYYY-MM-DD HH24:MI:SS') <= to_timestamp(concat('2024', '-12-25 23:59:59'), 'YYYY-MM-DD HH24:MI:SS ')
when '01' = '全年' then to_timestamp(concat(a.blood_discard_date), 'YYYY-MM-DD HH24:MI:SS') >= to_timestamp(concat('2024'-1, '-12-26 '), 'YYYY-MM-DD HH24:MI:SS ')
and to_timestamp(concat(a.blood_discard_date), 'YYYY-MM-DD HH24:MI:SS') <= to_timestamp(concat('2024', '-12-25 23:59:59'), 'YYYY-MM-DD HH24:MI:SS ')
when '01' = '季度1' then to_timestamp(concat(a.blood_discard_date), 'YYYY-MM-DD HH24:MI:SS') >= to_timestamp(concat('2024'-1, '-12-26 '), 'YYYY-MM-DD HH24:MI:SS ')
and to_timestamp(concat(a.blood_discard_date), 'YYYY-MM-DD HH24:MI:SS') <= to_timestamp(concat('2024', '-03-25 23:59:59'), 'YYYY-MM-DD HH24:MI:SS ')
when '01' = '季度2' then to_timestamp(concat(a.blood_discard_date), 'YYYY-MM-DD HH24:MI:SS') >= to_timestamp(concat('2024', '-03-26 '), 'YYYY-MM-DD HH24:MI:SS ')
and to_timestamp(concat(a.blood_discard_date), 'YYYY-MM-DD HH24:MI:SS') <= to_timestamp(concat('2024', '-06-25 23:59:59'), 'YYYY-MM-DD HH24:MI:SS ')
when '01' = '季度3' then to_timestamp(concat(a.blood_discard_date), 'YYYY-MM-DD HH24:MI:SS') >= to_timestamp(concat('2024', '-06-26 '), 'YYYY-MM-DD HH24:MI:SS ')
and to_timestamp(concat(a.blood_discard_date), 'YYYY-MM-DD HH24:MI:SS') <= to_timestamp(concat('2024', '-09-25 23:59:59'), 'YYYY-MM-DD HH24:MI:SS ')
when '01' = '季度4' then to_timestamp(concat(a.blood_discard_date), 'YYYY-MM-DD HH24:MI:SS') >= to_timestamp(concat('2024', '-09-26 '), 'YYYY-MM-DD HH24:MI:SS ')
and to_timestamp(concat(a.blood_discard_date), 'YYYY-MM-DD HH24:MI:SS') <= to_timestamp(concat('2024', '-12-25 23:59:59'), 'YYYY-MM-DD HH24:MI:SS ')
end
执行失败(语句1)
-2007: 第 9 行, 第 94 列[between]附近出现错误:
语法分析出错
用二分法,把sql简化一下,定位到具体报错的行