'WHERE 1 =1' in SQL Stored Procedure [duplicate]
Possible Duplicate:
Why would someone use WHERE 1=1 AND <conditions> in a SQL开发者_Go百科 clause?
I've been tasked with reviewing some SQL stored procedures and have seen many that look like the following:
SELECT
X, Y, Z
FROM
Table
WHERE
1 = 1
ORDER BY
X
Why would someone use '1 = 1' for the where clause?
Thanks!
It's common in dynamic SQL, in order to append additional criteria to a WHERE clause. Otherwise, it's useless and it is ignored by the optimizer.
possibly to dynamically add conditions to the where clause.
精彩评论