I am trying to pass a string value which is comma separated to birt report as parameter but failing
Java code
String userlist="\"a\",\"b\",\"c\"";
task.setParameterValue("userlist", userlist);
BeforeOpen has
params["userlist"].value.join("','");
SQL Query is
select * from users where name in (?)
I have already linked data set parameter to report parameter param_1 It's always giving me empty report even though DB table has 3 users. Any advise?
Know your tools: In this context, You have to understand SQL and the concept of bind variables. Javascript and BIRT. Unfortunately every single piece of code you posted is wrong (or at least incomplete).
But you are on the right track: You can modify the SQL text in the beforeOpen event of the database. I'll sketch the idea here:
In your SQL, replace the? with a placeholder like 'IN-LIST' (such that it is valid SQL).
You should still use the bind variable in the SQL (to avoid pitfalls caused by BIRT's caching mechanism), but in an effective no-op way, eg "where? is not null".
In the beforeOpen event of the data set, you can modify the SQL text:
"
around your search terms, which looks overly complicated, unless individual search terms may contain commas. You should now have a list of your search strings, eg ["a", "b", "c"]
.["'a"', "'b'", "'c'"]
.'a', 'b', 'c'
.this.queryText = query;
Probably there is also an example somewhere in the mists of the internet.
If you had invested five minutes more, you should have found an existing answer here on stack overflow: How to create a BIRT dataset that accepts multiple (CSV) values that it can be used inside "IN" clause in select statement , the only difference being that you are searching for a list of strings, while that question was about a list of numbers.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.