Hello I am new in this,
I have a 2 sql select statement.
this is the first sql statement:
3 Answers:
Simplest way is using a case statement, but it can also be achieved by using a terinary statement.
Try creating a parameter1 with 2 options. (SQL1 and SQL2).
Create another parameter2 which processes the first parameter with a java terinary statement as below.
$P{parameter1} == "SQL1" ? "paste your sql1 here without spaces/line breaks" : "paste your sql2 here without spaces/line breaks"
In the dataset and query editor, remove any existing SQL and paste $P!{parameter2}
Passing SQL1 into the parameter1 will pass the sql1, anything else will be evaluated to sql2.
Yes, Case when being the simplest.
The other option that the above answer gives is of "Conditional Parameter" stated as $!P{} which is quite efficient but I do not recommend the same in this situation for below mentioned reasons;
1) Case when is very simple
2) Conditional parameter increase the run time of the query compared to case when
3) May get complex and involves an additional parameter creation. however case when is operated upon a column value.
Moreover, Conditional parameter is genrally used in case of "where or From" clause in a query because if the conditional parameter is used in "Select" clause, the read fields from db would not work.
Hope this helps guys,
Regards,
KKriplani