sql拼语句例子

以查询为例:

查询条件依次为:1.name 为"昌吉市个体";2.cost为大于等于”400“ ;3.date满足时间段”dateBegin“”dateEnd“ 

表:Table1

  strsql="select * from Table1 where 1=1";

  if(!String.IsNullOrEmpty(name))

{

     strsql+="and name like '%昌吉市个体%'";

}

if(!String.IsNullOrEmpty(cost))

{

     strsql+="and cost>=400 ";

}

if(!String.IsNullOrEmpty(begin))

{

     strsql+="and date>=dateBegin and date<=dateEnd";

}

条件依次罗列

或使用case...when...then... 实现

 

posted on 2013-07-31 18:12  jyq_218  阅读(165)  评论(0)    收藏  举报

导航