db2查询返回0条记录

时间:2015-10-06 16:55:54

标签: sql db2 db2-400 ibm-db2

我正在尝试执行以下查询:

select * from trgdms.src_stm where trim(src_stm_code) in (select concat (concat('''', trim(replace(processed_src_sys_cd,',',''','''))),'''' ) from trgdms.batch_run_log where src_stm_cd_or_hub_cd='CTR' and file_process_dt='2015-06-19' and batch_id=42);

表trgdms.src_stm的src_stm_code列具有类似T19,T68,T73等的值。当我单独运行内部查询时,我确实得到了正确的结果:

select concat (concat('''', trim(replace(processed_src_sys_cd,',',''','''))),'''' ) from trgdms.batch_run_log where src_stm_cd_or_hub_cd='CTR' and file_process_dt='2015-06-19' and batch_id=42

结果:'T19','T68','T73'

想知道是否有人在db2中使用了类似的东西?

1 个答案:

答案 0 :(得分:0)

从内部查询中删除concat部分。连接值时,生成的值列表将被视为字符串,查询不会返回任何结果。

select * from trgdms.src_stm where trim(src_stm_code)
in (select trim(replace(processed_src_sys_cd,',',''',''')) from trgdms.batch_run_log 
    where src_stm_cd_or_hub_cd='CTR' and file_process_dt='2015-06-19' and batch_id=42);