${if}用法

筛选框显示内容:是/否;前端选择‘是’的时候就会把表中该字段有值的那条数据查出来,反之选择‘否’的时候,查出该字段为null的那条数据,不选则显示全部如何写where后的${if}:

image.pngimage.png后台设置:image.png

FineReport YANGNAN 发布于 2023-6-20 15:34 (编辑于 2023-6-20 16:08)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
0
Z4u3z1Lv6专家互助
发布于2023-6-20 15:37(编辑于 2023-6-20 16:18)

SELECT * FROM TABLE WHERE 1=1 ${IF(LEN(下拉)==0,"",IF(下拉="是"," AND CSCLOSER IS NOT NULL"," and  CSCLOSER IS NULL"))}

------------------

SELECT * FROM TABLE WHERE 1=1 ${switch(下拉,"是","AND CSCLOSER IS NOT NULL","否","CSCLOSER IS NULL",下拉,"")}

----------------

SELECT * FROM TABLE WHERE 1=1 ${if(len(p_sfgb)=0,""," AND (CASE WHEN ISNULL(b.cscloser,'')='' THEN 'FALSE' ELSE 'TRUE' END)='"+p_sfgb+"'" )}

---------------

终于清楚你的设置了:

1、控件值为 是/否 case的时候也应该是 是/否,不是true/false  (SQL结束处)

2、你要判断的是B表的字段,所以用 LEFT join B没用,A表的数据仍然全部显示,需要改成 INNER 或者 right JOIN

select m.cjy, b.cscloser, a.cexch_name, a.csocode,a.ddate,a.ccuscode,c.ccusname,b.cinvcode,i.cinvname,i.cinvstd,com.ccomunitname,b.iquantity,b.inum,b.inatunitprice, b.inatsum,qty,b.iquantity-isnull(qty,0) wfhqty ,i.cInvStd,l.cInvcName,b.iNatMoney,b.iTaxUnitPrice,dis.iiSum,b.iTaxRate,b.iNatUnitPrice,dis.iMoney from ${p_zt}..so_somain a inner join ${p_zt}..so_sodetails b on a.id=b.id left join (select isosid,sum(iquantity) qty ,sum(iNatMoney) iMoney,sum(inatsum)iisum from ${p_zt}..dispatchlist d left join ${p_zt}..dispatchlists e on d.dlid=e.dlid where 1=1 ${if(len(p_cuscode)=0,""," and ccuscode = '"+p_cuscode+"'")} ${if(len(p_fhbegindate)=0,""," and ddate >='"+fhbegindate+"'")} ${if(len(p_fhenddate)=0,""," and ddate <='"+p_fhenddate+"'")} group by isosid ) dis on b.isosid=dis.isosid left join customer c on a.ccuscode=c.ccuscode left join inventory i on b.cinvcode=i.cinvcode left join inventoryclass l on i.cinvccode=l.cinvccode left join computationunit com on i.cpucomunitcode=com.ccomunitcode left join dm_salebillvouchs_list m on m.ccusname =c.ccusname where 1=1 ${if(len(p_cuscode)=0,""," and a.ccuscode ='"+p_cuscode+"'")} ${if(len(p_sobegindate)=0,""," and a.ddate >='"+p_sobegindate+"'")} ${if(len(p_soenddate)=0,""," and a.ddate <='"+p_soenddate+"'")} ${if(len(p_wlfl)=0,""," and l.cInvcName ='"+p_wlfl+"'")} ${if(len(p_chbm)=0,""," and b.cinvcode ='"+p_chbm+"'")} ${if(len(p_ggxh)=0,""," and i.cinvstd ='"+p_ggxh+"'")} ${if(len(p_ddh)=0,""," and a.csocode ='"+p_ddh+"'")} ${if(len(p_bz)=0,""," and a.cexch_name ='"+p_bz+"'")} ${if(len(p_jy)=0 || p_jy='是' ,"", " and isnull(m.cjy,'') ='' " )} ${if(len(p_sfgb)=0,"", " and (case when isnull(b.cscloser,'')='' then '否' else '是' end)='"+p_sfgb+"'" )}

  • YANGNAN YANGNAN(提问者) 下拉指的是下拉框名称吧
    2023-06-20 15:38 
  • Z4u3z1 Z4u3z1 回复 YANGNAN(提问者) 是的 指控件名
    2023-06-20 15:39 
  • Z4u3z1 Z4u3z1 回复 YANGNAN(提问者) 确实改成switch免得括号打错位置
    2023-06-20 15:41 
  • YANGNAN YANGNAN(提问者) 回复 Z4u3z1 试过了,还是不对,选择是的时候,页面没数据,但是表中CSCLOSER字段有些是有值的
    2023-06-20 15:42 
  • Z4u3z1 Z4u3z1 回复 YANGNAN(提问者) 你是SqlServer?oracle?mysql?把你的SQL完整贴出来
    2023-06-20 15:47 
最佳回答
0
Gun鹏Lv5初级互助
发布于2023-6-20 15:55

SELECT * FROM  表名 WHERE 1=1${if(len(参数) == 0 ,"", " and 字段名='" + 参数+ "'")}

  • 2关注人数
  • 398浏览人数
  • 最后回答于:2023-6-20 16:18
    请选择关闭问题的原因
    确定 取消
    返回顶部