开发者

'WHERE 1 =1' in SQL Stored Procedure [duplicate]

开发者 https://www.devze.com 2023-01-23 02:13 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: Why would someone use WHERE 1=1 AND <conditions> in a SQL开发者_Go百科 clause?
This question already has answers here: Closed 12 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消