开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜