Solved

how can select distinct records within loop

Posted on 2004-04-20
7
369 Views
Last Modified: 2006-11-17
Since i can't do it with the distinct option, was wondering if there is a way to display a record
only once using a loop?
0
Comment
Question by:alberte
7 Comments
 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10870119
Why cant you use a dinstinct? What sql are you using??
0
 
LVL 11

Expert Comment

by:L00M
ID: 10870159
I assume you mean you've queried a database and now have a populated recordset.
For whatever reason, you can't use distinct in the query...

So, I would recommend converting the recordset to an array:
http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=161

Now that you have an array, sort it:
http://www.4guysfromrolla.com/webtech/012799-3.shtml

You could then enumerate through the array and check to see if the next row matches the previous row, if not copy the current row to an identical table.
If so, skip it and move on to the next until they don't match. At that point, copy the current row to the identical table, and set the new current row to the non matching row. (Confusing eh?)
In the end, your identical table will hold distinct results.
0
 

Author Comment

by:alberte
ID: 10870303
I don't think i will use an array, I finaly got a query to work but i get more records
then i need and i can't select distinct.
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10870312
Can you show us the query?
0
 
LVL 6

Accepted Solution

by:
sforcier earned 50 total points
ID: 10870563
Does this do what you want?

Dim oldVal
oldVal = ""

While Not(rs.EOF)
   if rs("fieldname") <> oldVal then
      oldVal = rs("fieldname")
      'Show data, or whatever it is you want to do
   end if
   rs.MoveNext
Wend
0
 
LVL 6

Expert Comment

by:sforcier
ID: 10870582
BTW, my code assumes that the recordset is sorted based on the duplicated field. Otherwise it won't work... that's an important thing to point out! :)
0
 
LVL 5

Expert Comment

by:waelothman
ID: 10870709
select Filed1,Field2 , Min(Filed3) as MField3 , Min(Filed4) as MField4 from tablename
group by  Filed1,Field2

where field 1, Field2 is what u wat to be distincit by
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Syntax Help on SP 4 57
Pass through dll 2 81
Passing Parameter to Stored Procedure 4 24
Adding Row and Cell on a table 14 18
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question