我正在为房产中介和租户建立一个网站。租户可以注册并填写他们想要的物业位置,包括街道,城镇和邮政编码。一旦他们注册,这会自动向具有符合这些搜索条件的属性的代理发送电子邮件。SQL Query根据用户输入查找匹配值
目前我的查询设置如下,以便它匹配街道,城镇或邮政编码。
<%
Dim rspropertyresults
Dim rspropertyresults_numRows
Set rspropertyresults = Server.CreateObject("ADODB.Recordset")
rspropertyresults.ActiveConnection = MM_dbconn_STRING
rspropertyresults.Source = "SELECT * FROM VWTenantPropertiesResults "
'WHERE (ContentStreet = 'Holderness Road') OR (ContentTown = 'Hull') OR (ContentPostCode = 'HU')
rspropertyresults.Source = rspropertyresults.Source& "WHERE (ContentStreet = '" & Replace(rspropertyresults__varReqStreet, "'", "''") & "'"
rspropertyresults.Source = rspropertyresults.Source& "OR ContentTown = '" & Replace(rspropertyresults__varReqTown, "'", "''") & "' "
rspropertyresults.Source = rspropertyresults.Source& "OR ContentTrimmedPostCode = '" & Replace(varPostcode, "'", "''") & "') "
rspropertyresults.Source = rspropertyresults.Source& "AND ((ContentBedRooms >= " & Replace(rspropertyresults__varBedroomsNoMin, "'", "''") & " "
rspropertyresults.Source = rspropertyresults.Source& "AND ContentBedRooms <= " & Replace(rspropertyresults__varBedroomsNoMax, "'", "''") & ") "
rspropertyresults.Source = rspropertyresults.Source& "AND (ContentPrice > = " & Replace(rspropertyresults__varPriceMin, "'", "''") & " "
rspropertyresults.Source = rspropertyresults.Source& "AND ContentPrice <= " & Replace(rspropertyresults__varPriceMax, "'", "''") & ")) " & varSQL & " "
rspropertyresults.Source = rspropertyresults.Source& "ORDER BY ContentPrice " & Replace(rspropertyresults__varSortWay, "'", "''") & " "
rspropertyresults.CursorType = 0
rspropertyresults.CursorLocation = 2
rspropertyresults.LockType = 1
rspropertyresults.Open()
rspropertyresults_numRows = 0
%>
但是,客户端已要求,而不是只对其中一个值匹配,它需要以这样的方式来工作,如果说街道和镇的比赛,然后通过电子邮件发送一个房地产经纪人,或者城市和邮政编码匹配,然后发送该物业代理。如你所想,我认为查询会变得相当复杂,但我不确定如何最好地设计这样的查询。
我想知道是否有人能够帮助或指向正确的方向吗?
+1:好的解决方案 - 也许在这种情况下UNION ALL会更好,因为无论如何你都是按ID分组的? – RedFilter 2009-09-10 13:59:01
Hey Quassnoi, 谢谢你的解决方案。我已经在视图中试过这个,首先看它是否正确执行。 (我也改变了ID到ContentID)。它执行,但不返回任何结果。 这可能是我有其他干扰结果的东西。我知道肯定有一些数据会匹配2或3个条件。 – doubleplusgood 2009-09-10 13:59:21
'@ OrbMan':对,谢谢。不仅更好,而且需要查询才能正常工作。 – Quassnoi 2009-09-10 14:03:42