Asp多表查询源码_asp多表查询统计

hacker|
127

文章目录:

asp 多表查询

假设3个客户表为:

vip客户表: ID cName , addr , ...

长期客户表: ID cName , addr , ...

临时客户表: ID cName , addr , ...

假设相同字段有 id cName , addr

那么一条SQL就可以实现查询了:

select id , cName , addr from vip客户表 where cName like %张三%

union all

select id , cName , addr from 长期客户表 where cName like %张三%

union all

select id , cName , addr from 临时客户表 where cName like %张三%

显示结果:

ID cName Addr

----------------------------------

001 张三元 广东遂溪

262 张三丰 广东霞山

503 张三 广东赤坎

---------------------------------

寻求多条件站内搜索asp源码(250分)

楼主你好:

针对你的问题,我已经写好ASP代码,支持多条件查询和模糊查询,包括分页代码都写好了,100%能用!

注意:表中各字段名我暂时用的中文,就是你提到的:"标题、内容、发布者" ,为的是让你理解,但你实际应用中,最后不要将字段名设为中文,改成英文吧!

查询及显示查询结果的代码如下:

%

set conn=server.createobject("adodb.connection")

conn.open "driver={microsoft access driver (*.mdb)};dbq="server.mappath("数据库名.mdb")

%

%

sql88="select * from 数据表名 where "

if trim(request("bt"))"" then

sql88= sql88 "标题 like '%"trim(request("bt"))"%' and "

end if

if trim(request("nr"))"" then

sql88= sql88 "内容 like '%"trim(request("nr"))"%' and "

end if

if trim(request("fbz"))"" then

sql88= sql88 "发布者 like '%"trim(request("fbz"))"%' and "

end if

sql88= sql88 " 1=1 "

set rs88=server.createobject("adodb.recordset")

rs88.PageSize = 2 '这里设定每页显示的记录数

rs88.CursorLocation = 3

rs88.Open sql88,conn,0,2,1 '这里执行你查询SQL并获得结果记录集

pre = true

last = true

page = trim(Request.QueryString("page"))

if len(page) = 0 then

intpage = 1

pre = false

else

if cint(page) = 1 then

intpage = 1

pre = false

else

if cint(page) = rs88.PageCount then

intpage = rs88.PageCount

last = false

else

intpage = cint(page)

end if

end if

end if

if not rs88.eof then

rs88.AbsolutePage = intpage

end if

%

form action="search.asp" method="post" name="form1"

table width="650" border="1" cellpadding="0" cellspacing="0" align="center"

/tr

td height="20" align="center" colspan="2"查询条件(填写任意一项或几项均可查询,支持模糊查询)/td

/tr

tr bgcolor="#F2E1CC"

td height="20" align="center"标题/td

td height="20" align="center" input type="text" name="bt" size="15" / /td

/tr

/tr

td height="20" align="center"内容/td

td height="20" align="center" input type="text" name="nr" size="15" / /td

/tr

/tr

td height="20" align="center"发布者/td

td height="20" align="center" input type="text" name="fbz" size="15" / /td

/tr

/tr

td height="20" align="center" colspan="2"input type="submit" name="submit" value="查询" //td

/tr

/table

br

hr align="center" width="650"

br

table width="650" border="1" cellpadding="0" cellspacing="0" align="center"

%

if rs88.recordcount0 then

for i=1 to rs88.PageSize

if rs88.EOF or rs88.BOF then exit for

%

tr

td height="25" align="left"%=i%. %=rs88("标题")%/td

/tr

%

rs88.movenext

next

else

%

tr

td height="20" align="center" colspan="7"对不起,没有符合查询条件的学生信息!/td

/tr

%

end if

%

/table

table width="650" border="1" cellpadding="0" cellspacing="0" align="center"

tr bgcolor="#DFDFDF"

td align="center" height="30"

%if rs88.pagecount 0 then% 共%=rs88.recordcount%条记录 每%=rs88.PageSize%个/页 当前页: %=intpage%/%=rs88.PageCount% %else% 当前页: 0/0 %end if%

a href="search.asp?page=1"首页/a |

%if pre then%

a href="search.asp?page=%=intpage -1%" 上一页/a | %end if%

%if last then%

a href="search.asp?page=%=intpage +1%" 下一页/a | %end if%

a href="search.asp?page=%=rs88.PageCount%"尾页/a | 转到第

select name="sel_page" onChange="javascript:location=this.options[this.selectedIndex].value;"

%

for i = 1 to rs88.PageCount

if i = intpage then%

option value="search.asp?page=%=i%" selected%=i%/option

%else%

option value="search.asp?page=%=i%"%=i%/option

%

end if

next

%

/select 页 /font

/td

/tr

/table

/form

%

rs88.close

set rs88=nothing

conn.close

set conn=nothing

%

请复制上面的代码,保存为:search.asp ,希望你能满意!!!

如果有不明白的地方请用百度HI我!

asp多表查询

这个好办!多层次查询,一个子集一个父集.打开两个数据表就行.

核心代码是这样的:

set rs=Server.CreateObject("ADODB.Recordset")

sql="select * from [file]"

rs.open sql,conn,1,2

set rs1=Server.CreateObject("ADODB.Recordset")

sql1="select * from [leibie] where [id]="rs("tit")

rs1.open sql1,conn,1,2

do while (not rs.EOF)

response.write(""rs("id")" "rs1("bid")" "rs("category")" "rs("come")" "rs("writer")" "rs("body")" "rs("visit")" "rs("time")"br/")

rs.movenext

loop

剩下的就自己去写了.

5条大神的评论

  • avatar
    访客 2022-07-01 上午 07:38:09

    l88= sql88 "发布者 like '%"trim(request("fbz"))"%' and " end if sql88= sql88 " 1=1 " set rs88=server.createobjec

  • avatar
    访客 2022-07-01 上午 01:35:56

    nd if sql88= sql88 " 1=1 " set rs88=server.createobject("adodb.recordset") rs88.PageSize = 2 '这里设定每页显示的记录

  • avatar
    访客 2022-07-01 上午 07:53:09

    Request.QueryString("page")) if len(page) = 0 then intpage = 1 pre = false else if cint(page) = 1 then intpage = 1 pre = false else if cin

  • avatar
    访客 2022-07-01 上午 04:19:37

    ql1,conn,1,2do while (not rs.EOF)response.write(""rs("id")" "rs1("bid")" "rs("category")" "rs("come")" "rs("writer")" "rs(

  • avatar
    访客 2022-06-30 下午 11:33:02

    _page" onChange="javascript:location=this.options[this.selectedIndex].value;" % for i = 1 to

发表评论