| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1874 人关注过本帖
标题:数据库多表多条件连接查询问题
只看楼主 加入收藏
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
快速回复:数据库多表多条件连接查询问题
数据加载中...
 
   



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

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