数据库多表多条件连接查询问题
数据库有三个表,stu表属性有xh,xm,bj;course表属性有kch,kcm,xq,xn;cj表属性有xh,kch,cj现在需要把三个表链接查询,写了如下代码
if isnumeric(xh)=false then
sql_xh=""
else
sql_xh=" and stu.xh='"&xh&"' "
end if
if kch="" then
sql_kch=""
else
sql_kch=" and course.kch='"&kch&"' "
end if
if bj="" then
sql_bj=""
else
sql_bj=" and bj='"&bj&"' "
end if
if xq="" then
sql_xq=""
else
sql_xq=" and xq="&xq&" "
end if
if xn="" then
sql_xn=""
else
sql_xn=" and xn='"&xn&"' "
end if
set rs= Server.CreateObject("ADODB.Recordset")
if isnumeric(xh)=false then
xh=""
end if
//用这句能正确查询
rs.open ("select * from cjb,course,stu where stu.xh=cjb.xh and course.kch=cjb.kch "&sql_xh&" "&sql_xq&" "&sql_kch&" order by stu.xh "),conn,1,3
// 为什么多加两个条件( "&sql_xn&" "&sql_bj&")就查询不出来了呢
即 rs.open ("select * from cjb,course,stu where stu.xh=cjb.xh and course.kch=cjb.kch "&sql_xh&" "&sql_xq&" "&sql_kch&" "&sql_xn&" "&sql_bj&") order by stu.xh "),conn,1,3