Jump to content

list of comma separated values


Recommended Posts

Hi experts,

I have a report where i am getting multiple account ids say 1 and 2 and  3 and 4 and  5

I need to pass all these account ids to a subreport as a parameter .

The subreport SQL will have a clause :- accountid in $p{accountid}

so in $p{accountid} i need a comma separated list of account ids.

but these accountids are returned rowwise(5 separate rows) in master report.


can you please tell me how can i prepare a comma seprated list of accountids to pass to my subreport.





so in $p(



Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic


I'm not sure if this is what you are asking for but you could try to add the values to a variable. And then pass that variable to the subreport. This can be done by grouping the report (by country in my example):

Country               City

England              London

England              Cambridge

England              Oxford

Country Footer $V{City_List}

The Contry_List variable would be populated like this:

Variable Class: String

Calculation: Nothing

Reset Type: Group

Reset Group: Country

Increment Type: None

Variable Expression: see code below

Initial Value Expression: ""  (Make sure to set this to an empty String!)






"".equalsIgnoreCase($V{City_List}) ?$F{city} == null ? $V{City_List}:$V{City_List}+""+$F{city}.trim():$F{city} == null ? $V{City_List}:$V{City_List}.contains($F{city}.trim()) ? $V{City_List} : $V{City_List}+", "+$F{city}.trim()
Link to comment
Share on other sites

Hi phantastes,

Thanks a lot for ur reply. I was also thinking in the same lines. But i didn't know how to implement it.

Can i have the values in the variable as comma separated strings such as :- '1000','1001','1002'

Also can you kindly explain me the variable expression code :-

"".equalsIgnoreCase($V{City_List}) ?
$F{city} == null ? $V{City_List}:$V{City_List}+""+$F{city}.trim():
$F{city} == null ? $V{City_List}:$V{City_List}.contains($F{city}.trim()) ? $V{City_List} : $V{City_List}+", "+$F{city}.trim()

A brief walkthrough will help me understand.

Thanks a lot in anticipation





Link to comment
Share on other sites


Yes you can a string such as '1000','1001','1002' by just adding the single quotes to the exrpession below. I've added it to the code.

The expression adds the field value to the variable if the variable is not null. It also adds a comma before (and now a single quote before and after) the field. There is some extra checks to handle the first field being added to the variable (by not adding a comma before the first value).

I'm also adding the trim() method to make sure there is no blank space at the end of the string.

I hope that helps!


"".equalsIgnoreCase($V{City_List}) ?$F{city} == null ? $V{City_List}:$V{City_List}+"'"+$F{city}.trim()+"'":$F{city} == null ? $V{City_List}:$V{City_List}.contains($F{city}.trim()) ? $V{City_List} : $V{City_List}+",'"+$F{city}.trim()"'"
Link to comment
Share on other sites

  • 2 years later...

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...