0

选择所有行(取消 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。它工作正常,但没有更好的方法吗?

4

2 回答 2

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 不熟悉

于 2013-10-24T10:39:37.800 回答
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";
于 2013-10-24T10:52:06.867 回答