harish0191 Posted November 25, 2016 Share Posted November 25, 2016 i have tried giving value in different format but nothing is working out #example 1default value of $P{From_Date} : new java.util.Date(2010,01,01)default value of $P{To_Date} : new java.util.Date(2016,11,11)#example 2 $P{From_Date} : 1.1.2013$P{To_Date} : 11.11.2016QUERY:selecttbl1.cantReqNo as OrderNumb, tbl2.empname as Employee,tbl1.canteen as ServicePlace, convert(datetime,tbl1.serviceDate,103) as ServiceDate,tbl3.itemName as FoodItem, tbl1.totalAmt as Cost,tbl1.status as Status,tbl4.deptname as DepartmentfromcanteenRequisition tbl1 , employee tbl2,canteenRequstionDetails tbl3, department tbl4wheretbl1.empNo=tbl2.empno and tbl1.cantReqNo=tbl3.cantReqNo and tbl4.Deptid=tbl1.createdDept and tbl1.empNo=200045 and replace(tbl1.canteen,' ','')= 'sitecanteen'and tbl1.serviceDate > $P{From_Date} and tbl1.serviceDate < $P{To_Date}group bytbl1.cantReqNo, tbl2.empname ,tbl1.canteen ,tbl1.serviceDate,tbl3.itemName , tbl1.totalAmt,tbl1.status,tbl4.deptname Link to comment Share on other sites More sharing options...
Solution joseng62 Posted November 25, 2016 Solution Share Posted November 25, 2016 If using relative dates Then create parameter in jasperstudio example Name: "datefrom"Class: net.sf.jasperreports.types.date.DateRangePrompting: you decideDefault value: new net.sf.jasperreports.types.date.DateRangeBuilder("MONTH-1").toDateRange()Explained "MONTH-1", you can use DAY, WEEK, YEAR.Then create second parameter in jasperstudio for the query. ExampleName: "FROM_DATE"Class: java.util.DatePrompting:Default value: $P{datefrom}.getEnd()Follow same steps for to dateQuery Example:select "columns" from table where "datefield" between $P{FROM_DATE} and $P{DATE_TO} For none relative datesOnly create 2 parameters, TO and FROM DATESExampleName: "FROM_DATE"Class: java.util.DatePrompting: you decideDefault value: new Date((new Date()).getTime()-7*24*60*60*1000) You can set the time period for now date just do new Date()If you have an issue with the date format, then either format the date field sql side to be same as jasper side or format jasper parameter to meet sql fields date format. If you just want to hardcode test. Then default string value should work. "2016-01-01" set paramter as string type. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now