0

I am trying to write logic for advanced search which has lot of fields. Based on user inputs I have to build the query dynamically. The oracle query has exists clause also.

At present I have a chain of switch cases which helps me in forming the query. But this has become very complex procedure, editing the logic to build a query has become very difficult.

Other than switch case is there any other way to build query dynamically. Please let me know

  • Have you think in generating a class that does the 'Query Building' due to parameter and data you give to it. for example, create a class, that has a method called addrestriction wich recives the information of a where clause, incluiding columm, operator and value and then implement a method called toSQL that generates the SQL query as a String for you to use it? you can SQandal try [here](http://code.google.com/p/sqandal/) – icrovett Apr 09 '13 at 13:43

2 Answers2

0

Just generic suggestion adding 1=1 in where clause makes thing easier.
This might help Why would someone use WHERE 1=1 AND <conditions> in a SQL clause?
PS: Also update your question with specific problem otherwise it is very likely to be get closed.

Community
  • 1
  • 1
Ajinkya
  • 22,324
  • 33
  • 110
  • 161
0

There is EasyQuery (http://devtools.korzh.com/easyquery/) solution but it's implemented for ASP.NET as far as I know. However, they have a jQuery-based client-side library which could be useful in your case.