数据集if判断用那个sql,带参数

为啥里面加了一个if,外面这个参数就没有了,然后里面的if去掉,外面这个参数才能用

${if((OA='1'),"select *

       from newsoft_cs.oa_wt_temp tmp

left join newsoft_cs.oa_wt t on tmp.file_id = t.file_id

where t.status in ('S','A','ST') and

${if(len(zt) == 0,"","and t.status in ('" + zt + "')")}

${if(len(dybh) == 0,"","and tmp.print_code in ('" + dybh + "')")}

${if(len(sfz) == 0,"","and tmp.user_id in ('" + sfz + "')")}

${if(len(khmc) == 0,"","and tmp.customer_name in ('" + khmc + "')")}

${if(len(strxm) == 0,"","and tmp.user_name in ('" + strxm + "')")}

${if(len(stime) == 0,"","and tmp.begin_time >= ('" + stime + "')")}

${if(len(etime) == 0,"","and tmp.end_time < ('" + etime + "')")}

",

"select * from newsoft_cs.oa_wt_view 

WHERE 1=1

${if(len(zt) == 0,"","and t.status in ('" + zt + "')")}

${if(len(dybh) == 0,"","and tmp.print_code in ('" + dybh + "')")}

${if(len(sfz) == 0,"","and tmp.user_id in ('" + sfz + "')")}

${if(len(khmc) == 0,"","and tmp.customer_name in ('" + khmc + "')")}

${if(len(strxm) == 0,"","and tmp.user_name in ('" + strxm + "')")}

${if(len(stime) == 0,"","and tmp.begin_time >= ('" + stime + "')")}

${if(len(etime) == 0,"","and tmp.end_time < ('" + etime + "')")}

"

)}

image.png

image.png

FineReport 我在等风也等你 发布于 2022-9-2 09:05 (编辑于 2022-9-2 09:10)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共3回答
最佳回答
0
snrtuemcLv8专家互助
发布于2022-9-2 09:08(编辑于 2022-9-2 09:16)

${}里面就能在${}了

语句拷贝出来,我给你改

===============

${if(OA='1',"select * from newsoft_cs.oa_wt_temp tmp left join newsoft_cs.oa_wt t on tmp.file_id = t.file_id where t.status in ('S','A','ST')"+ 

if(len(zt) == 0,""," and t.status in ('" + zt + "')")+

if(len(dybh) == 0,""," and tmp.print_code in ('" + dybh + "')")+

if(len(sfz) == 0,""," and tmp.user_id in ('" + sfz + "')") +

if(len(khmc) == 0,""," and tmp.customer_name in ('" + khmc + "')") +

if(len(strxm) == 0,""," and tmp.user_name in ('" + strxm + "')") +

if(len(stime) == 0,""," and tmp.begin_time >= ('" + stime + "')") +

if(len(etime) == 0,""," and tmp.end_time < ('" + etime + "')"), 

"select * from newsoft_cs.oa_wt_view WHERE 1=1"+ 

if(len(zt) == 0,""," and t.status in ('" + zt + "')")+

if(len(dybh) == 0,""," and tmp.print_code in ('" + dybh + "')")+

if(len(sfz) == 0,""," and tmp.user_id in ('" + sfz + "')") +

if(len(khmc) == 0,""," and tmp.customer_name in ('" + khmc + "')") +

if(len(strxm) == 0,""," and tmp.user_name in ('" + strxm + "')") +

if(len(stime) == 0,""," and tmp.begin_time >= ('" + stime + "')") +

if(len(etime) == 0,""," and tmp.end_time < ('" + etime + "')")

)

}

最佳回答
1
RiveryLv5中级互助
发布于2022-9-2 09:24(编辑于 2022-9-2 09:27)

因为后面的${}条件实际上是一样的,所以只需要对不一样的部分判断就行了的,亲测没问题

${if((OA='1'),"select * from newsoft_cs.oa_wt_temp tmp

left join newsoft_cs.oa_wt t on tmp.file_id = t.file_id

where t.status in ('S','A','ST') 

",

"select * from newsoft_cs.oa_wt_view 

WHERE 1=1"

)}

${if(len(zt) == 0,"","and t.status in ('" + zt + "')")}

${if(len(dybh) == 0,"","and tmp.print_code in ('" + dybh + "')")}

${if(len(sfz) == 0,"","and tmp.user_id in ('" + sfz + "')")}

${if(len(khmc) == 0,"","and tmp.customer_name in ('" + khmc + "')")}

${if(len(strxm) == 0,"","and tmp.user_name in ('" + strxm + "')")}

${if(len(stime) == 0,"","and tmp.begin_time >= ('" + stime + "')")}

${if(len(etime) == 0,"","and tmp.end_time < ('" + etime + "')")}

最佳回答
0
weibwLv7高级互助
发布于2022-9-2 09:07(编辑于 2022-9-2 09:24)

~~

  • 2关注人数
  • 766浏览人数
  • 最后回答于:2022-9-2 09:27
    请选择关闭问题的原因
    确定 取消
    返回顶部