Nearly every project have search panel and custom filters in my company. It is hard to create when project has too much filter.
Is there any good design pattern for creating custom sql queries for using with filters?
I always write something like this:
commandText = "SELECT * FROM XXX "
innerJoinCommand = ""
whereCommand = ""
if (??.length > 0)
whereCommand += "AND ??? "
if (??.Count > 0)
innerJoinCommand += "??? "
//...
if (innerJoinCommand.length > 0)
commandText += innerJoinCommand
if (whereCommand.length > 0)
commandText += "WHERE " + whereCommand