Is it poor practice to build an SQL query using WHERE 1=1 AND ...
- by Rob
I'm writing a script that builds an SQL query by concatenating the string and adding conditions to the WHERE clause as needed.
Would it be better practice to use WHERE 1=1 so that the first condition is satisfied and the script can just concatenate an AND x = 'y' to the query, or should I write the extra code to check if a clause has been added and if not, add the AND ?
Confusing question, I know. Let me know if I need to be more clear.
Rob