|
-
Dec 3rd, 2002, 06:06 AM
#1
Thread Starter
Fanatic Member
How to sort a multi-column data?
How to sort a multi-column data? That is, suppose an array contains following columns
LastName
FirstName
Country
City
I want to sort them by LastName, FirstName, Country, City.
What is the way to that? One obvious solution appears to concatenate each field value as a single string and sort then, but is there any better solution? Also, if any field is number, the above said method won't work easily? Any suggestion?
Please don't post database commands (like order by). I like to know how to do it programmatically.
thanks
Life is a one way journey, not a destination. Travel it with a smile and never regret anything.
Yesterday is history, tomorrow is a mystery, today is gift - that's why we call it present.
-
Dec 3rd, 2002, 08:22 AM
#2
Sounds a little like a recursive loop, but perhaps worse.
One way
First you need to compare on the first field - for the whole array
Then you need to compare the second field ONLY if the first fields match.
Then you need to compare the third field ONLY if the second nad first fields match
...And so on...
Whether you can do this in one loop or several is up to you.
I think (personally) that it has to be several - so the array is sorted properly, but this may hit your processing time.
I'd be interested in your results, if you record times and come up with a way in one loop and a way using several loops to which is faster and produces the correct results. Post up wen you've done it.
Vince
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Dec 3rd, 2002, 08:55 AM
#3
Thread Starter
Fanatic Member
Thanks for suggestion. Can you tell me how does the databases (Oracle, SQL Server etc.) implement this kind of sort?
Life is a one way journey, not a destination. Travel it with a smile and never regret anything.
Yesterday is history, tomorrow is a mystery, today is gift - that's why we call it present.
-
Dec 3rd, 2002, 01:29 PM
#4
Hyperactive Member
if ur using ADO recordsets then...
I want to sort them by LastName, FirstName, Country, City
if u get that record in ADO recordset 'Rs' then u can sort on multiple fields ..
VB Code:
rs.sort="LastName, FirstName, Country, City"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|