MYSQL如何在WHERE子句中取消或取消WHERE子句

时间:2013-10-24 10:34:57

标签: mysql asp.net drop-down-menu

选择所有行的最佳值是什么(取消WHERE子句)?

  <select id="ddlSelect">
    <option value = ???? > -- SELECT ALL -- </option>
    <option value = "1" > 1 </option>
    <option value = "2" > 2 </option>
  </select>

选择查询

"SELECT EMPLOYEE_NAME WHERE EMPLOYEE_DEPARTMENT_ID = " + ddlSelect.Value;

对于-- SELECT ALL --,我尝试了1 OR 1 =1。它工作正常,但不是更好的方法吗?

2 个答案:

答案 0 :(得分:2)

<select id="ddlSelect">
  <option value = "all" > -- SELECT ALL -- </option>
  <option value = "1" > 1 </option>
  <option value = "2" > 2 </option>
</select>

并在您的 .net 代码中

String strQuery = "SELECT EMPLOYEE_NAME FROM table_name";

if(ddlSelect.Value != "all") {
   strQuery += " WHERE EMPLOYEE_DEPARTMENT_ID = " + ddlSelect.Value;
}

抱歉,我不熟悉.net

答案 1 :(得分:0)

var query = '';
if($('#ddlSelect').val() > 0)
     query  = "SELECT EMPLOYEE_NAME from table_name WHERE EMPLOYEE_DEPARTMENT_ID = " + $('#ddlSelect').val() ;
else
     query  = "SELECT EMPLOYEE_NAME from table_name";