标题:数据库多表多条件连接查询问题
只看楼主
ou1111
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:87
专家分:162
注 册:2010-10-26
结帖率:100%
 问题点数:0 回复次数:0 
数据库多表多条件连接查询问题
数据库有三个表,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
搜索更多相关主题的帖子: course false 数据库 
2012-02-16 20:49



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-361029-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.121525 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved