本例实现根据用户选择不同的查询条件查询显示报表。按我的报表业务来演示。我的报表要查询条件是起始时间,结束时间,站点,有票,没票,55以上,55以下分别设置报表参数对应这几个查询条件。start,end,station,ticketed,unticketed,up55t,below55t其中有票,没票,55以上,55以下只能选择一种情况页面代码我就不写了,大概就是如果选择哪个就设置哪个值为1,在报表的数据集的script里写上:var condition = "and 1=1 order by Weight desc"; var start = reportContext.getParameterValue("start");var end = reportContext.getParameterValue("end");var ticket = reportContext.getParameterValue("ticketed");var unticket = reportContext.getParameterValue("unticketed");var up55t = reportContext.getParameterValue("up55t");var below55t = reportContext.getParameterValue("below55t");var st = reportContext.getParameterValue("station");var station = "and DetectionStationNo = '"+ st +"'";
if(st == "all"){ station = "and 1=1";}
if(ticket==1){condition = " and VehClass=1 order by Weight desc";}if(unticket==1){condition = " and VehClass=0 order by Weight desc ";}if(up55t==1){condition = " and Weight>55000 order by OverPercent desc";}if(below55t==1){condition = " and not Weight>=55000 order by Weight desc";}然后就是this.queryText =" ... .." + condition;
当然有时候我们可能是一种情况就是选择一类,也可以选择全部,比如上面的站点,可能选择所有站点,那就在页面如果用户选择全部,就个特定值过来,我是指定如果是全部,就不加这个条件,1=1大概就这些,大家自己试试。
相关资源:birt报表的动态sql