Jump to content
We've recently updated our Privacy Statement, available here ×

How to compare a value from two different queries in Jasper reports


manicarina

Recommended Posts

I have an employee record when evere a value is changed for example if the salary of the employee is changed a new version of the employee record is created in the table as given below

EMPLOYEE TABLE
EMP IDENAMESALARYVERSION
100WULFRIC50001
100WULFRIC60002

SELECT * FROM EMPLOYEE WHERE EMP_ID = $P{P_KOMBINATIONSNR}

SELECT * FROM EMPLOYEE WHERE EMP_ID = 100 AND VERSION = (($F{VERSION}-1))

In the intial report i'll be showing the highest version record and I need to higlight the Changed salary value as Red color.

Please Give me solution to do this in Ireport.

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi.. I've not tried this one. but I can give you some idea.

Just place some static text lable/a color filled ractangle over the SALARY field.. and write printWhen expression for the placed  static text label/coloer filled rectangel..

Give condition something like this :  If version number=max(version number) then print the colored text lable/color filled expression. [This expression should be written in java).

Thanks :)

Link to comment
Share on other sites

Convert the 2 rows into columns by using LEA/LAG funcation or the  PIVOT table funcation in oracle as follows

CREATE TABLE EMPLOYEE
(
   ID        NUMBER,
   ENAME     VARCHAR2 (15),
   SALARY    NUMBER,
   VERSION   NUMBER
);



INSERT INTO EMPLOYEE (  ENAME, ID, SALARY,   VERSION)VALUES ( 'WULFRIC', 100, 5000, 1);
INSERT INTO EMPLOYEE (  ENAME, ID, SALARY,   VERSION)VALUES ( 'WULFRIC', 100, 6000, 2);
COMMIT;


SELECT B.ID,
       B.ENAME,
       B.SALARY,
       B.OLD_SALARY,
       ROWNUM RN
  FROM (SELECT A.*,
               ROWNUM RN,
               LEAD (SALARY) OVER (ORDER BY VERSION DESC) AS OLD_SALARY
          FROM (SELECT ENAME,
                       ID,
                       SALARY,
                       VERSION
                  FROM EMPLOYEE
                 WHERE ID = 100 AND VERSION = 2
                UNION
                SELECT ENAME,
                       ID,
                       SALARY,
                       VERSION
                  FROM EMPLOYEE
                 WHERE ID = 100 AND VERSION = 1
                ORDER BY VERSION DESC) A
         WHERE ROWNUM <= 2) B
 WHERE ROWNUM <= 1;

 

 

IDENAMESALARYOLD_SALARYRN
100WULFRIC6,0005,0001

You'll get the above result and use conditional style formatting in IReport.

Thank you.

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...