T_SQL-查詢條件語法

T_SQL-查詢條件語法

String sql ="select * from 資料表";
          sql+ = "where 1=1 "; //
where 條件恆成立
       

if (條件欄位!= null && 條件欄位 != "")
     sql += "and company_id='" + conditionCompanyID+"'";

if...

String sql = "select cell_phone,backup_mail,apply_date,finish_date from TB_APPLY_PASSWORD ";
        sql += "where 1=1 ";
        if (conditionMailID != null && conditionMailID != "")
            sql += "and mail_id='"+conditionMailID+"'";
        if (conditionCellPhone != null && conditionCellPhone != "")
            sql += "and cell_phone="+conditionCellPhone;
        if (conditionStartDate != null && conditionStartDate != "")
             sql += "and convert(char(12),apply_date,111)>='"+conditionStartDate+"'";