Uderc programming article aggregator sites

Stuck in a complicated situation

Answers: Have 8 answers
I have to come up with a query for report which is dependent on what is selected in the 7 drop boxes.
startdate: enter text
enddate: enter text
Department: Deptname
Group:drop down (values like All, Supervisor, Manager, etc)
Classification:drop down (all drop downs have values like above)
Shift:drop down
Report Category:drop down
Overtime Type:drop down
Sort Type:drop down
So a user can select "all" job types or a particular one like "carpenter"..
If the person selects "all" then I dont want to put a where clause or have a condition/restriction in my query ..
I am not sure how I can have a query for this situation without multiple if elses for each situation.. Any ideas?
I will have to say if group = "All" then dont include condition
if group = "All" and Shift="A''" then dont include both
if reportcategory ="All" and ... and so many conditions??? Is there a way out of this complication?
The best answer: rephrasing the question:
I have select * from a,b,c where .........
Now I want to add not only d_column = "1" but also "d"
itself after from so that it becomes:
select * from d,a,b,cThen you just have more strings to dynamically generate. Example:
String fromList = "a,b,c";
String columnList = "x1,x2,y3";
String whereClause = "someColumn=? AND someOtherColumn >= ?...";
if (someCondition) {
fromList += ",d";
whereClause += " AND d_column=1";
columnList += "d_field1,d_field2";
String sql = "SELECT " + columnList + " FROM " + fromList + " WHERE " + whereClause;