标题:[求助]SQL语句中怎样同时查询一个表中的两个字段
只看楼主
gmqq
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2006-11-2
 问题点数:0 回复次数:12 
[求助]SQL语句中怎样同时查询一个表中的两个字段

问题:SQL语句中怎样同时查询一个表中的两个字段

相关源码:Sql="Select * From MovieList where title like '%"&keyword&"%' Order BY ID Desc"
title是标题名的字段,我想在增加一个产品内容的content字段,都在同一个表内

Dim Page
Page=Request("Page")
PageSize = 15
Dim Rs,Sql
If ClassID="" Then
Sql="Select * From MovieList where title like '%"&keyword&"%' Order BY ID Desc"
Else
Sql="Select * From MovieList where content like '%"&keyword&"%' Order BY ID Desc"
End if
Set Rs=Server.CreateObject("ADODB.Recordset")
Rs.open Sql,Conn,3,3
Rs.PageSize = PageSize
Totalfilm=Rs.RecordCount
Pgnum=Rs.Pagecount
If Page="" or Clng(Page)<1 Then Page=1
If Clng(Page) > Pgnum Then Page=Pgnum
If Pgnum>0 Then Rs.AbsolutePage=Page
If Rs.Eof Then
搜索更多相关主题的帖子: SQL语句 表中 字段 Order 
2006-11-17 23:30
gmqq
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2006-11-2
得分:0 
我这样写了但是不对Sql="Select * From MovieList where title like '%"&keyword&"%' OR(AND) content like '%"&keyword&"%' Order BY ID Desc"
问题在那里??????????
2006-11-18 01:22
gmqq
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2006-11-2
得分:0 

我试着用Sql="Select * From MovieList where title like '%"&keyword&"%' or content like '%"&keyword&"%'"

获得成功,但搜索不到关健字内容或有“空格”时就会报错如下:

错误类型:
Microsoft JET Database Engine (0x80040E14)
内存溢出
/vod/so/go.asp, 第 70 行


浏览器类型:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)

网页:
POST 87 ??? /vod/so/go.asp

POST Data:
Times=1&keyword=%C7%EB%CA%E4%C8%EB%B9%D8%BC%FC%D7%D6%21&%CC%E1%BD%BB=%B8%F8%CE%D2%CB%D1



相关问题:怎样让搜索时,让一句话中只是关健变红,其它字不变红?

源码A:Response.Write "<td width=""145"" height=""55"">&nbsp;<a href=""../Html/"&Rs("ID")&".html"" target=""_blank""><font color=red>"&Rs("Title")&"</font> </a></td>"
结果出错:出现整个标题都变红了,

源码B:Response.Write "<td width=""145"" height=""55"">&nbsp;<a href=""../Html/"&Rs("ID")&".html"" target=""_blank"">"(&Rs("Title")&" ,""&keyword&"","<font color=red>"&keyword&"</font>")</a></td>"

结果出错:错误类型:
Microsoft VBScript 编译器错误 (0x800A03EA)
语法错误
/vod/so/go.asp, line 97, column 112
Response.Write "<td width=""145"" height=""55"">&nbsp;<a href=""../Html/"&Rs("ID")&".html"" target=""_blank"">"(&Rs("Title")&" ,""&keyword&"","<font color=red>"&keyword&"</font>")</a></td>"


请大家邦我看看,错在那里,感谢

[此贴子已经被作者于2006-11-18 2:31:26编辑过]

2006-11-18 01:52
做人很低调
Rank: 5Rank: 5
等 级:贵宾
威 望:18
帖 子:1268
专家分:0
注 册:2006-8-2
得分:0 
第一个问题:
改成这个试试
Sql="Select * From MovieList where title like '%"&trim(keyword)&"%' or content like '%"&trim(keyword)&"%'"
这种错误原因也可能是不支持日文关键字查询

第二个问题: 要用到Replace("字符串","要被替代的字","替代后的字")这个函数
Response.Write "<td width='145' height='55'>&nbsp;<a href='../Html/"&Rs("ID")&".html' target='_blank'>"&Replace(rs("title"),trim(keyword),"<font color='red'>"&trim(keyword)&"</font>")&" </a></td>"

其实我很低调,只是你不知道...
2006-11-18 09:05
gmqq
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2006-11-2
得分:0 
感谢楼上的朋友,第二个问题中的字符串被我忽略所以出错,在你的指导下我重写语句后成功,

但是第一个问题:Sql="Select * From MovieList where title like '%"&trim(keyword)&"%' or content like '%"&trim(keyword)&"%'"
这条语句只可以把空格识别,但当搜索不到关健字的时候,还是会报错,如下:
错误类型:
Microsoft JET Database Engine (0x80040E14)
内存溢出
/vod/so/go.asp, 第 69 行

我试着只查询一个表里的一个字段,代码如下:Sql="Select * From MovieList where title like '%"&keyword&"%' Order BY ID Desc"

这样一切都是正常的,但是同一个表下的content字段却不可以被查询,如果我这样写:
Sql="Select * From MovieList where title like '%"&trim(keyword)&"%' or content like '%"&trim(keyword)&"%'Order BY ID Desc"
查询时就出现:错误类型:
Microsoft JET Database Engine (0x80040E14)
内存溢出
/vod/so/go.asp, 第 69 行

看来我的SQL语句还是有问题,还得请我看一下啊,最好修正后的SQL语句,可以实现“关健字”+“关健字”的查询方式,麻烦了,谢谢

2006-11-18 13:10
做人很低调
Rank: 5Rank: 5
等 级:贵宾
威 望:18
帖 子:1268
专家分:0
注 册:2006-8-2
得分:0 
试着用括号把2个LIKE的子句括上呢

where (title like '%"&trim(keyword)&"%') or (content like '%"&trim(keyword)&"%')Order BY ID Desc

象这样 试试

其实我很低调,只是你不知道...
2006-11-18 13:16
gmqq
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2006-11-2
得分:0 
这样会无法搜索:
错误类型:
Microsoft VBScript 编译器错误 (0x800A0409)
未结束的字符串常量
/vod/so/go.asp, line 65, column 125
Sql="Select * From MovieList where (title like '%"&trim(keyword)&"%') or (content like '%"&trim(keyword)&"%')Order BY ID Desc

我在后面加上 " 进行语句结束后:
错误类型:
Microsoft JET Database Engine (0x80040E14)
内存溢出
/vod/so/go.asp, 第 69 行

看来我只有把整个贴出来了,如下:
<style type="text/css">
<!--
body,td,th {
font-size: 12px;
}
-->
</style><!--#include File="Conn.asp" -->
<!--#include file="1.asp" -->
<%
If Session("AdminName")="0" and Session("Purview")="0" Then
Response.Redirect "Error.asp?id=005"
Else
Response.Write "<Html>"
Response.Write "<Head>"
Response.Write "<Title>移动影院 - 影视搜索 </title>"
Response.Write "<Meta Http-Equiv=""Content-Type"" Content=""Text/Html; CharSet=Gb2312"">"



Response.Write "</Head>"
Response.Write "<body topmargin=""2"">"
Response.Write "<div align=""center"">"
Response.Write "<center>"
Response.Write "<table border=""0"" cellpadding=""0"" cellspacing=""0"" bgcolor=""#CCCCCC"" style=""border-collapse: collapse"" bordercolor=""#111111"">"
Response.Write "<tr align=""center"" bgcolor=""#EEEEEE"">"
Response.Write "<td height=""25"" colspan=""3"" width=""100%""><p align=""center""><font color=""#FFFFFF"">&nbsp;"

Response.Write "</tr>"
Response.Write "<tr>"
Response.Write "<td height=""24"" bgcolor=""#EEEEEE"" width=""583""><p align=""center"">&nbsp;"
ClassID=Request("ClassID")
keyword=Request("keyword")
Set RsClass= Server.CreateObject("ADODB.Recordset")
RsClass.open "Select * From Class",Conn,1
If RsClass.Eof Then
Response.Write "暂时没有栏目"
Else

do while not RsClass.Eof


RsClass.Movenext
Loop
End If
RsClass.Close
Response.Write "</td>"
Response.Write "</tr>"
Response.Write "<tr align=""center"" valign=""top"" bgcolor=""#FFFFFF"">"
Response.Write "<td height=""293"" colspan=""3"" width=""100%"">"
Response.Write "<table border=""0"" width=""100%"" cellspacing=""0"" cellpadding=""0"" align=""center"">"
Response.Write "<form action=""go.asp"" method=""post"">"
Response.Write "<br><tr>"
Response.Write "<td width=""100%"" align=""center"">"
Response.Write "<input type=""text"" name=""keyword"" size=""50"" style=""font-size: 12px; border-left-width: 1; border-right-style: solid; border-right-width: 1; border-top-width: 1; border-bottom-style: solid; border-bottom-width: 1"">"
Response.Write "&nbsp;<input type=""submit"" value=""移动搜索"">"
Response.Write "</form>"
Response.Write "<table width=""100%"" border=""1"" cellpadding=""0"" cellspacing=""0"" bordercolor=""#CCCCCC"" style=""border-collapse: collapse"">"


Dim Page
Page=Request("Page")
PageSize = 15
Dim Rs,Sql
If ClassID="" Then
Sql="Select * From MovieList where (title like '%"&trim(keyword)&"%') or (content like '%"&trim(keyword)&"%') Order BY ID Desc"
Else
End if
Set Rs=Server.CreateObject("ADODB.Recordset")
Rs.open Sql,Conn,3,3
Rs.PageSize = PageSize
Totalfilm=Rs.RecordCount
Pgnum=Rs.Pagecount
If Page="" or Clng(Page)<1 Then Page=1
If Clng(Page) > Pgnum Then Page=Pgnum
If Pgnum>0 Then Rs.AbsolutePage=Page
If Rs.Eof Then
Response.Write " </a><a href=""http://www.139com.cn""><Font Color=#FF0000> 提示 : 无搜索结果,请点击这里提交想要查询的影视关健字!搜索引擎会在你提交后自动查找收录! >>>点击返回移动主页!</a>"
Else
Response.Write "<tr>"
Response.Write "<td width=""100"" height=""25"" align=""center"" bgcolor=""dddddd"">图片预览</td>"
Response.Write "<td width=""150"" height=""25"" align=""center"" bgcolor=""dddddd"">电影名称</td>"
Response.Write "<td width=""230"" height=""25"" align=""center"" bgcolor=""dddddd"">简介</td>"
Response.Write "<td width=""80"" height=""25"" align=""center"" bgcolor=""dddddd"">类别</td>"
Response.Write "<td width=""50"" height=""25"" align=""center"" bgcolor=""dddddd"">点播次数</td>"
Response.Write "<td width=""160"" height=""25"" align=""center"" bgcolor=""eeeeee"">主演</td>"

Response.Write "</tr>"
Count=0
Do While Not (Rs.Eof Or Rs.Bof) And Count<Rs.PageSize
Response.Write "<tr>"
Response.Write "<td width=90 height=60 align=center >"
Response.Write("<a target=_blank href=""../Html/"&Rs("ID")&".html"" target=""_blank"">")
Response.Write("<img width=90 height=60 src="&rs("pic")&">")
Response.Write("</a><br>")


Response.Write "<td width='145' height='55'>&nbsp;<a href='../Html/"&Rs("ID")&".html' target='_blank'>"&Replace(rs("title"),trim(keyword),"<font color='red'>"&trim(keyword)&"</font>")&" </a></td>"

Response.Write "<td width=300 height=55 align=center >"
if len(rs("content"))>60 Then
response.write (mid(rs("content"),1,60))
response.write (".....")
else
response.write (rs("content"))
end if
response.write "</a></td>"


Response.Write "<td width=""80"" height=""25"" align=""center"">"&Rs("CLASSID")&" </a></td>"
Response.Write "<td width=""50"" height=""25"" align=""center""><Font Color=#FF0000>"&Rs("hits")&" </a></td>"
Response.Write "<td width=""160"" height=""70"" align=""name""strlen=""40"">"&Rs("name")&"</a></td>"

Response.Write "</tr>"
Rs.Movenext
Count=Count+1
Loop
End If
Response.Write "</table>"
Response.Write "</td>"
Response.Write "</tr>"
Response.Write "<tr bgcolor=""#EEEEEE"">"
Response.Write "<td height=""25"" colspan=""3"" align=""center"" width=""100%"">"
Response.Write "<Form Method=""Post"" action=""go.asp"">"
Response.Write "[第<Font Color=#FF0000>"& Page &"</font>页/共"& Rs.PageCount &"页] "
If Page=1 Then
Response.Write "[首 页] [上一页] "
Else
Response.Write "[<a href=""go.asp?Page=1&ClassID="& ClassID &""">首 页</a>] "
Response.Write "[<a href=""go.asp?Page="& Page-1 &"&ClassID="& ClassID &""">上一页</a>] "
End If
If Rs.PageCount-Page<1 Then
Response.Write "[下一页] [尾 页]"
Else
Response.Write "[<a href=""go.asp?Page="& Page+1 &"&ClassID="& ClassID &""">下一页</a>] "
Response.Write "[<a href=""go.asp?Page="& Rs.PageCount &"&ClassID="& ClassID &""">尾 页</a>]"
End If
Response.Write " 共[<Font Color=#FF0000>"& Totalfilm &"</font>]部电影"
Response.Write " 转到:<Input Type='Text' Name=""Page"" Size=2 Maxlength=10 value="""& Page &""" align=""center"">"
Response.Write "<Input Type=""Submit"" value=""Goto"" Size=2 Name=""Submit"">"
Response.Write "<Input Type=""Hidden"" value="""& ClassID &""" Name=""Hidden"">"
Rs.Close
Response.Write "</td>"
Response.Write "</tr>"
Response.Write "<tr>"
Response.Write "<td height=""25"" align=""center"" bgcolor=""#EEEEEE"" colspan=""3""><font color=""#FFFFFF"">&copy;"

Response.Write "</tr>"
Response.Write "</table>"
Response.Write "</center>"
Response.Write "</div>"
Response.Write "</body>"
Response.Write "</html>"
End If %>



2006-11-18 13:33
gmqq
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2006-11-2
得分:0 
错误类型:
Microsoft VBScript 编译器错误 (0x800A0409)
未结束的字符串常量
/vod/so/go.asp, line 65, column 126
Sql="Select * From MovieList where (title like '%"&trim(keyword)&"%') or (content like '%"&trim(keyword)&"%') Order BY ID Desc

我增加"完结语句后:Sql="Select * From MovieList where (title like '%"&trim(keyword)&"%') or (content like '%"&trim(keyword)&"%') Order BY ID Desc"

错误类型:
Microsoft JET Database Engine (0x80040E14)
内存溢出
/vod/so/go.asp, 第 69 行

这条语句还是不对????


相关源码:Dim Page
Page=Request("Page")
PageSize = 15
Dim Rs,Sql
If ClassID="" Then
Sql="Select * From MovieList where title like '%"&trim(keyword)&"%' or content like '%"&trim(keyword)&"%'"
Else
End if
Set Rs=Server.CreateObject("ADODB.Recordset")
Rs.open Sql,Conn,3,3
Rs.PageSize = PageSize
Totalfilm=Rs.RecordCount
Pgnum=Rs.Pagecount
If Page="" or Clng(Page)<1 Then Page=1
If Clng(Page) > Pgnum Then Page=Pgnum
If Pgnum>0 Then Rs.AbsolutePage=Page
If Rs.Eof Then
Response.Write " </a> 提示 : 无搜索结果,请点击这里提交想要查询的关健字!搜索引擎会在你提交后自动查找收录! >>>点击返回移动主页!</a>"
Else

在搜索不到关健字的时候,我调用最后一句进行报错提示,麻烦邦我看一下,是不是后面的语句引起的

[此贴子已经被作者于2006-11-18 13:43:55编辑过]

2006-11-18 13:37
gmqq
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2006-11-2
得分:0 
要是方便请加我QQ:393195095万分感谢  做人很低调
2006-11-18 13:47
做人很低调
Rank: 5Rank: 5
等 级:贵宾
威 望:18
帖 子:1268
专家分:0
注 册:2006-8-2
得分:0 
content这个字段什么类型?

其实我很低调,只是你不知道...
2006-11-18 13:52



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




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

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