Is it poor practice to build an SQL query using WHERE 1=1 AND ...
Posted
by Rob
on Stack Overflow
See other posts from Stack Overflow
or by Rob
Published on 2010-04-12T15:42:01Z
Indexed on
2010/04/12
15:43 UTC
Read the original article
Hit count: 312
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
© Stack Overflow or respective owner