rand_id department_id department_name
30 3001 武汉市
40 3001010 蔡甸区
40 3001011 江夏区
40 3001012 黄陂区
40 3001013 新洲区
30 3002 黄石市
40 3002011 大冶市
40 3002012 阳新县
Select Case UploadDepart
Case "ALL " '选择所有部门
sqlWhere = " where t.rand_id <=40 "
Case "_RAND_20 " '选择省局级
sqlWhere = " where t.rand_id =20 "
Case "_RAND_30 " '选择市州级
sqlWhere = " where t.rand_id =30 "
Case "_RAND_40 " '选择县级
sqlWhere = " where t.rand_id =40 "
Case else '选择某个具体部门
sqlWhere = " where t.department_id = ' " & UploadDepart & " ' "
End Select
sql = "select t.department_name,t.department_id from t_department t " & sqlWhere & " order by t.department_id "
具体代码是这样的!如果我通过一个textbox(也就是 ' " & UploadDepart & " ')获得了武汉市这个字段,那么应该怎么写语句同时把蔡甸区,江夏区,黄陂区和新洲区同时从数据库中查找出来?
------解决方案--------------------
sql = "SELECT * FROM table WHERE department_id LIKE (SELECT department_id FROM table WHERE department_name = ' "&UploadDepart& " ') "
------解决方案--------------------
使用模糊查询
字段 like '% "关键字 "% '