首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

为何查询语句中经常会有"1=1"

2012-07-19 
为什么查询语句中经常会有11目的是动态查询,查询语句先加上WHERE 11,然后后面的条件不论是有一个或者

为什么查询语句中经常会有"1=1"

目的是动态查询,查询语句先加上WHERE 1=1,然后后面的条件不论是有一个或者多个都可以直接写为AND <condition>.

?

dim sqlstmt as new StringBuildersqlstmt.add("SELECT * FROM Products")sqlstmt.add(" WHERE 1=1") ''// From now on you don't have to worry if you must ''// append AND or WHERE because you know the WHERE is thereIf ProductCategoryID <> 0 then  sqlstmt.AppendFormat(" AND ProductCategoryID = {0}", trim(ProductCategoryID))end ifIf MinimunPrice > 0 then  sqlstmt.AppendFormat(" AND Price >= {0}", trim(MinimunPrice))end if
?

?

?

http://stackoverflow.com/questions/242822/why-would-someone-use-where-1-1-and-conditions-in-a-sql-clause

热点排行