Skip to main content
Participating Frequently
September 18, 2012
Answered

recordset filtering from another recordset

  • September 18, 2012
  • 20 replies
  • 3348 views

okay, here is my problem in a nut shell

i have a search page to display results based on a zip code location(lat/long) coordinates.  The first recordset on the page shows the builder information that is within the search parameters:

<%

Dim builder_ID__longValue

builder_ID__longValue = "1"

If (Request.Querystring("long") <> "") Then

  builder_ID__longValue = Request.Querystring("long")

End If

%>

<%

Dim builder_ID

Dim builder_ID_cmd

Dim builder_ID_numRows

Set builder_ID_cmd = Server.CreateObject ("ADODB.Command")

builder_ID_cmd.ActiveConnection = MM_home_detective_STRING

builder_ID_cmd.CommandText = "SELECT builder_info_ID,     ( 3959 * acos( cos( radians(39.8227054) ) * cos( radians(builder_info.lat ) )     * cos( radians(builder_info.lng) - radians(?)) + sin(radians(39.8227054))     * sin( radians(builder_info.lat)))) AS distance FROM home_detective.builder_info HAVING distance < 75 ORDER BY distance"

builder_ID_cmd.Prepared = true

builder_ID_cmd.Parameters.Append builder_ID_cmd.CreateParameter("param1", 5, 1, -1, builder_ID__longValue) ' adDouble

Set builder_ID = builder_ID_cmd.Execute

builder_ID_numRows = 0

%>

<%

Dim Repeat1__numRows

Dim Repeat1__index

Repeat1__numRows = -1

Repeat1__index = 0

builder_ID_numRows = builder_ID_numRows + Repeat1__numRows

%>

Then from here i have another table that has the builder_ID value listed with all of the school districts that they work within.

What i want to do is to display the search results for the School district *** BUT NOT DISPLAY THE DUPLICATED VALUES *** here is the code i am using

<%

While ((Repeat1__numRows <> 0) AND (NOT builder_ID.EOF))

%>

<%

Dim school_district__MMColParam

school_district__MMColParam = "1"

If (builder_ID.fields.item("builder_info_ID") <> "") Then

  school_district__MMColParam = builder_ID.fields.item("builder_info_ID")

End If

%>

<%

Dim school_district

Dim school_district_cmd

Dim school_district_numRows

Set school_district_cmd = Server.CreateObject ("ADODB.Command")

school_district_cmd.ActiveConnection = MM_home_detective_STRING

school_district_cmd.CommandText = "SELECT DISTINCT school_district FROM home_detective.school_district WHERE builder_ID = ?"

school_district_cmd.Prepared = true

school_district_cmd.Parameters.Append school_district_cmd.CreateParameter("param1", 5, 1, -1, school_district__MMColParam) ' adDouble

Set school_district = school_district_cmd.Execute

school_district_numRows = 0

%>

  <div><%=(builder_ID.Fields.Item("builder_info_ID").Value)%>

  <%=(school_district.Fields.Item("school_district").Value)%>

    </div>

  <%

  Repeat1__index=Repeat1__index+1

  Repeat1__numRows=Repeat1__numRows-1

  builder_ID.MoveNext()

Wend

%>

as you can see, it displays the results but if 2 builders have the same school district, it displays that school district twice.  I only want the DISTINCT values

any ideas?

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer bregent

Yup, this part of the script works perfectly


Great. So now try this query which uses the previous as a sub-query:

SELECT DISTINCT school_district FROM home_detective.school_district WHERE builder_ID IN

(SELECT builder_info_ID FROM home_detective.builder_info

WHERE  ( 3959 * acos( cos( radians(39.8227054) ) * cos( radians(builder_info.lat ) )  * cos( radians(builder_info.lng) - radians(?)) + sin(radians(39.8227054))  * sin( radians(builder_info.lat)))) < 75)

20 replies

sudarshan.t
Inspiring
September 18, 2012

You have the answerkey in your post itself.

R&D DISTINCT parameter. That should do the trick.

banbearAuthor
Participating Frequently
September 18, 2012

unfortunatly that doesn't do the trick. It filters through each line per the builder_ID from the original recordset and just displays the results.  It DOES duplicate the school_district fields because i am assuming that they are different builder_ID's associated with them.

The problem is that i need to filter the school districts based on the builder_ID's so that only the correct ones show based on the search criteria

example:

user searches for zip code 08029

search result pages displays all the builders within 50 miles of the zip code 08029

then, i want to display the school districts that each of those builders has.  Some builders may have the same school district so i want to prevent those duplicates from occuring.

sudarshan.t
Inspiring
September 18, 2012

Ouch. I wish this was PHP. Would've been work it out for you very quickly. I know the basic parameters but not a pro ASP guy! Let's wait for an expert to throw in some advice. I seem interested in getting to know this too