Fetching the N-th row from the query.

Wanted to ask if it's possible in Jasper Reporting to do the following:
Query Result:
ID      Name
------- ------------
1001    NICK
1010    BOB
1022    TOM
I have text in REPORT that needs to fetch all the names,
The creditor, Nick with id 1001, bla bla bla bla, and the Guarantor BOB with id 1010 Bla bla bla bla, and guy who vouches TOM with ID 1022, bla bla lba.
Is it possible to fetch the second of third row of query in Variable.
I tried like this but NO LUCK. I put this on Variable Expression:
($F{ID} == 1001) ? $F{NAME} : ""
Thank you very much in advance, appreciate your time.
hekuran23's picture
Joined: Mar 6 2014 - 5:45am
Last seen: 8 years 4 months ago

2 Answers:

Shouldn't you be doing this in your SQL statement? Getting Nick's id and Nick's Guarantor and the guy who vouches in one sql statement?

If the rows you're fetching is always 3 and in that particular order, just create variables. Remember, variables are evaluated in order they appear in the outline view.

hozawa's picture
Joined: Apr 24 2010 - 4:31pm
Last seen: 3 years 1 month ago

Hozawa, Thank you very much for your effort.

Actually I'm new in Jasper Report, and don't have much knowledge. I could concatenate whole statement in one line, but I do not know how to fetch the second line and put in the report, I tried to do this "$F{ID} == 1001" in variables, but it's only TRUE when you put the ID of First row, and gives the name, but once you put a variable with id 1010, it does not fetch the name but only returns NULL.

Could you help me solve this.

Thank you.

hekuran23 - 8 years 4 months ago

For just 2 rows, create 2 variables $V{Customer} and $V{Guarantor} in this order in Outline view.

Set $V{Customer} = $V{Guarantor}

$V{Guarantor} = $F{Name}

JasperReports evaluates variables top down according to Outline view so $V{Customer} will be set to what $V{Guarnator} was before it's updated with $F{Name}

hozawa's picture
Joined: Apr 24 2010 - 4:31pm
Last seen: 3 years 1 month ago