sql 问题

select a.* ,b.sc_name

from tdepart_transfer_sj a

left join tbosc_sc_base b on a.CONTRACT_NO=b.sc_no

where 1=1

(case when '${hz}'=0 then out_depart_no in (select c_id  

from tm_tree 

where 1 = 1

and c_type = '自主经营体'

and ${rights("belong_amb_id",hierarchy,p_depart,departs_amb)})

or in_depart_no in (select c_id  

from tm_tree 

where 1 = 1

and c_type = '自主经营体'

and ${rights("belong_amb_id",hierarchy,p_depart,departs_amb)})

when '${hz}'=1 then out_depart_no in (select c_id  

from tm_tree 

where 1 = 1

and c_type = '自主经营体'

and ${rights("belong_amb_id",hierarchy,p_depart,departs_amb)})

when '${hz}'=2 then in_depart_no in (select c_id  

from tm_tree 

where 1 = 1

and c_type = '自主经营体'

and ${rights("belong_amb_id",hierarchy,p_depart,departs_amb)}) else '' end )

${if(years=0 || len(years)<1,""," and to_number(to_char(transfer_date,'yyyy'))="+years)}

${if(months=0 || len(months)<1,""," and to_number(to_char(transfer_date,'mm'))="+months)}

${if(len(replace(p_search_txt,"'",""))=0, "", " and (transfer_no like '%"+replace(p_search_txt,"'","")+"%' or contract_no like '%"+replace(p_search_txt,"'","")+"%') ")}

where 后面添加了case  when  导致错误了。我也不知道错在哪里啊 。

FineReport 吴浩 发布于 2018-12-18 11:36
1min目标场景问卷 立即参与
回答问题
悬赏:4 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
0
axingLv6专家互助
发布于2018-12-18 11:51

不能在case when then 。。。这里写布尔表达式,应该得到结果后再去判断

  • 吴浩 吴浩(提问者) 你的意思是我then 后面不能这么写sql 是吗
    2018-12-18 11:54 
  • axing axing 回复 吴浩(提问者) 是的,可以整合起来简化下
    2018-12-18 11:55 
  • 吴浩 吴浩(提问者) 回复 axing 不好简化没我是用一个参数代表3种状态。
    2018-12-18 14:02 
  • axing axing 回复 吴浩(提问者) 你这个${rights(\"belong_amb_id\",hierarchy,p_depart,departs_amb)}是什么意思,自定义的函数吗
    2018-12-18 14:03 
  • 吴浩 吴浩(提问者) 回复 axing 对,这个可以忽略,固定的。
    2018-12-18 14:05 
最佳回答
1
wocaocao69Lv0见习互助
发布于2018-12-18 11:41

第一个1=1后面 是不是少了个 and

  • 吴浩 吴浩(提问者) 忘了,加了and 过后显示缺少关键字
    2018-12-18 11:47 
  • wocaocao69 wocaocao69 回复 吴浩(提问者) 感觉你的case when 语法用的不对,case when else end
    2018-12-18 11:51 
  • 3关注人数
  • 481浏览人数
  • 最后回答于:2018-12-18 11:51
    请选择关闭问题的原因
    确定 取消
    返回顶部