出现这种情况怎么办?select * from Table where and A

解决方案 »

  1.   

    sql = "select * from Table where 1=1"
    If A<>"" Then sql = sql & " and " & A
    If B<>"" Then sql = sql & " and " & B
    If C<>"" Then sql = sql & " and " & C
    If D<>"" Then sql = sql & " and " & D
      

  2.   

    能说一下 你的语言环境是用的什么呢?
    Asp  Php Jsp 或者其他的呢
    如果你用Jsp 的话 
    我有个好的办法给你解决
      

  3.   

    <?PHP
    $sqlWhere = 'id > 0';//这儿随你怎么写if($A != '')$sqlWhere.=" and A的表达式";
    if($B != '')$sqlWhere.=" and B的表达式";
    ?>
      

  4.   

    我一般是这样用
    <?PHP
    $sqlWhere = 'id > 0';//这儿随你怎么写if($A != '')$sqlWhere.=" and A的表达式";
    if($B != '')$sqlWhere.=" and B的表达式";$sql = "select * from Table where $sqlWhere";
    ?>欢迎加入PHP爱好者群: 30169840
      

  5.   

    Php 的东东  我就不懂了
    不过我的方法是
    初始的 sql  变量 不需要有 Where 关键字就写 Select ... from  table_name 
    定义一个 临时变量 tempSql
    然后就判断 A,B,C,D
    if(A不等于空)
    tempSql = tempSql  + "and name="+A---按照上面的方法 你把B , C , D  都判断了判断完成后构造的语句格式为  and name = A and age=B
    最后 再 判断 tempSql 不为空的情况下 去掉tempSql 变量的前三个字符 也就是把 第一个 and 去掉
    sql = sql + "where "+ tempSql
      

  6.   

    $sql = 'select * from Table where 1=1';
    if($A!='') $sql = $sql . ' and ' . $A;
    if($B!='') $sql = $sql . ' and ' . $B;
    if($C!='') $sql = $sql . ' and ' . $C;
    if($D!='') $sql = $sql . ' and ' . $D;
    其中$A之类的是xxx ='xxx'的形式;
      

  7.   

    LZ要的是那种多条件检索的查询,
    LS的满足要求
      

  8.   

    判断非空,拼sql字符串.一般先加 where 1=1 ,不会出现where and A了
      

  9.   

    hookee() 正解where 1=1 和 where 1 != 1 在sql中会经常用到1=1 为后面加东西做好铺垫,1 != 1 得到表的结构
      

  10.   

    $aWhere[] = " 1=1 ";
    if(!empty($A))
    $aWhere[] = $A;
    if(!emtpy($B))
    $aWhere[] = $B;
    if(!empty($C))
    $aWhere[] = $C;
    if(!empty($D))
    $aWhere[] = $D;$sWhere = join(' and ', $aWhere);
    $sSql = "select * from tbl where $sWhere order by id desc";
      

  11.   

    $condition = "";
    $link_symbol = "";
    if($a)
    {
       $condition .= "$link_symbol $a";
       $link_symbol = "and";
    }
    依次类推