INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Selecting Distinct values form a recordset?

Selecting Distinct values form a recordset?

(OP)
Hi

I have a VB6 program that is using data from an MS SQL database.

Just wondered if there was an easy way to retrieve or filter DISTINCT values from a recordset, ie.without using a seperate Select statement

I am creating a chart and need  distinct values from the recordset to become the axis lables.

RE: Selecting Distinct values form a recordset?

Not that I'm aware of.  You could either make another recordset using distinct, and spend another round trip to the db, or you could iterate the recordset and pull distinct values.

RE: Selecting Distinct values form a recordset?

I totally agree with BobRodes suggestions.  Look into the dictionary object if you want to check for distinct values.

Swi

RE: Selecting Distinct values form a recordset?

Well, in effect, if you use the dictionary object, you're still iterating through all the items in the source recordset and using the exists method to check for duplicates.  My feeling is that this technique has less steps, though:

1.   Sort the recordset on the values you want to pull.
2.   On each iteration of the recordset, store the current value in a variable.
3.   On each iteration of the recorset but the first one, compare the current value to that in the variable.  If not the same, copy the value to the destination.

How does that look?

Bob

RE: Selecting Distinct values form a recordset?

I would be very interested to see which one is faster.  If I get some free time I will try it out.

Swi

RE: Selecting Distinct values form a recordset?

(OP)
Thankyou both BobRodes and Swi for your replies.

I have to admit, I have never come across the Dictionary object, i will look into it.

Thanks again.

Regards

Alan Edwards

RE: Selecting Distinct values form a recordset?

The Dictionary object is certainly worth looking into.  It's kind of like a collection object, but lighter and in many ways with more functionality.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close