473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

How to write Advance Searching SQL Query

Fary4u
273 100+
Baically how i can differentiate Query like i need 1st Query + including 2nd part + including 3rd part & so on & so forth

SQL Query i need is like this

Residential (Not Commercial) but Tolet (Not Sale) and 2 bedrooms (Not 3) with in 40 to 70 Price (<>) Rent also include in City (Not Area) but Area (With in City chose Area) Town
EXPLAIN
i've got 4 property in DB 3 are Sale & 1 are Rented + 3 Sale Property i've got 1 in Commercial & 2 in Residential Property + 2 Residential one's i've got 1 in x area & 2 in y area (but Y is Commercial) is these both are in some city & 1 in some other city + 1 is less then 1000 & 1 is greater then 1000

these filed i've got in database, it's taking values from Dropdown + Combo box + Radio & Text filed

Here is Coding i'm writing database fields as well but this coding is working but not detail search.
Expand|Select|Wrap|Line Numbers
  1. chkres = Request.form("chkres")         ' ( DB Filed as Type - Resd, Comcl, Othr )
  2. chkcom = Request.form("chkcom")     ' ( DB Filed as Type - Resd, Comcl, Othr )
  3. chkoth = Request.form("chkoth")         ' ( DB Filed as Type - Resd, Comcl, Othr )
  4. strCat = Request.form("strCat")         ' ( DB Filed as Category_ID - Sale or Tolet )
  5. intPrice = Request.form("intPrice")      ' ( DB Filed as Price comprasion Min )
  6. intPricem = Request.form("intPricem")      ' ( DB Filed as Price compras  Max )
  7. strbed = Request.form("strbed")         ' ( DB Filed as Beds - 0 <> 1 , 2 , 3 )
  8. strText = cstr(Request.form("strText")) '(DB Filed as city & town Text Search)
  9.  
  10.     if chkres = "yes" then
  11.         chkres = "Residential"
  12.     end if
  13.     if chkcom = "yes" then
  14.         chkcom = "Commercial"
  15.     end if
  16.     if chkoth = "yes" then
  17.         chkoth = "Others"
  18.     end if    
  19.  
  20.         strTextWhere = " and (uCase(db_city) like '%"&strText&"%'"
  21.         strTextWhere = strTextWhere & " or uCase(db_town) like '%"_
  22.             & strText & "%')"    
  23.  
  24. '  intPriceWhere = " and Price < " &intPrice
  25.    intPriceWhere = " and Price >= " & intPrice & " and Price <=" & intPricem 
  26.  
  27.         strCatWhere = " and property.category_ID = '" &strCat&"'"
  28.  
  29.         strChk1 = " and property.Type = '" &strChk1&"'"            
  30. '        strChk2 = " and property.Type = '" &strChk2&"'"        
  31. '        strChk3 = " and property.Type = " & strChk3    ' Check box options
  32.  
  33.         strbed = " and property.Beds < '" &strbed&"'"
  34.  
  35.     set Conn = Server.CreateObject("ADODB.Connection")
  36.     Conn.Open ConString
  37.  
  38.     sqlText = "select distinct(property.property_ID), " 
  39.     sqlText = sqlText & "Property.Price ,"
  40.     sqlText = sqlText & "Property.Style ,"
  41.     sqlText = sqlText & "Property.Category_ID ,"
  42.     sqlText = sqlText & "Property.Beds ,"    
  43.     sqlText = sqlText & "Property.address ,"    
  44.     sqlText = sqlText & "Property.offer ,"    
  45.     sqlText = sqlText & "Property.Image_1 ,"    
  46.     sqlText = sqlText & "Property.Type "
  47.     sqlText = sqlText & "from property " 
  48.     sqlText = sqlText & "where property.property_ID = "
  49.     sqlText = sqlText & "property.property_ID"
  50. sqlText = sqlText & strCatWhere & strTextWhere & intPriceWhere & strChk3 & etc.
  51.  
  52.  
it's quite completed query if some body help me to solve this i'm realy thx.
Hope u get my point.
Mar 14 '08 #1
4 1843
Fary4u
273 100+
Hi i'm just can't sort it out can u plz look the coding give me the possiblity reply
Mar 17 '08 #2
Fary4u
273 100+
What the simplest way to run this kind of problem ?
Mar 18 '08 #3
jhardman
3,406 Expert 2GB
What the simplest way to run this kind of problem ?
Instead of replying to bump your post, please consider sending a PM to an forum expert. In answer to your question, I often form complex queries like this:
Expand|Select|Wrap|Line Numbers
  1. query = "SELECT * FROM properties WHERE "
  2. if request("maxPrice") <> "" then
  3.    query = query & "Price <= " & request("maxPrice") & " AND "
  4. end if
  5.  
  6. if request("minPrice") <> "" then
  7.    query = query & "Price >= " & request("minPrice") & " AND "
  8. end if
  9.  
  10. if request("tolet") <> "" then
  11.    query = query & "tolet = 'True' AND "
  12. end if
  13.  
  14. 'etc.  Notice the where clause of the query ends with " AND " no matter what
  15.  
  16. 'you need to trim the " AND " off the end
  17. query = left(query, len(query)-5)
Let me know if this helps.

Jared
Mar 18 '08 #4
jhardman
3,406 Expert 2GB
Right before you send this query to the db, check to see what the final output is:
Expand|Select|Wrap|Line Numbers
  1. response.write "Query: " & query & "<br>" & vbNewLine
printing out this query is a good place to start troubleshooting. If you don't see the problem just by looking, you can copy the query into a SQL query analyzer which will tell you if you got the right answer.

Please print out this query and then tell me what you get.

Jared
Mar 24 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: donald | last post by:
Hi all, I have a website running asp (about to move to asp.net soon though) which has a list of DVD's I have the various pages I want, last 10, listing, full listing ect, but the one page i can't...
3
by: aaj | last post by:
This is a simple question compared to some of the stuff that gets asked (and answered) here, but sometimes its easy to over look the simpler things. I've been working with databases for a few...
7
by: Scott | last post by:
I need help to modify the code below to pass url variables from a framset. The click to run this will be in the mainFrame. This script works well in a non-frame page. Grabs the current url...
1
by: Robert Oschler | last post by:
I read a while back that MySQL will only use one index per query. (If this is not so, please tell me and point me to a doc that gives a good explanation of MySQL's current index usage policy). ...
4
by: Jordan S. | last post by:
Using .NET 2.0 (C#) I'm writing a small app that will have a "Person" class that exposes FirstName and LastName properties. At runtime, a "People" collection will be populated with a few thousand...
1
by: lorirobn | last post by:
Hi, I have a query that I have been using as a record source for a form with no problems. I just created a new "addnew" form, and added 20 records to the table with this form. The problem I...
8
by: Allan Ebdrup | last post by:
What would be the fastest way to search 18,000 strings of an average size of 10Kb, I can have all the strings in memory, should I simply do a instr on all of the strings? Or is there a faster way?...
10
by: rohit | last post by:
hi, i am developing a desktop search.For the index of the files i have developed an algorithm with which i should be able to read and write to a line if i know its line number. i can read a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.