I have a non-normalized table that I'm trying to get certain results from and its posing a bit of a problem. The table is organized as follows (all fields are text):
ID FirstName LastName Address1 City State Zip DateConfirmed
12345 Bugs Bunny 123 Hello Street Topeka KS 22222 12/1/1985
12345 Bugs Bunny KS 22222 12/1/1985
12345 Bugs Bunny 555 What Lane Topeka KS 22222 1/1/1980
54321 Elmer Fudd 234 Looney Street Detriot MI 88888 11/5/2000
54321 Elmer Fudd 678 Penny Lane Detroit MI 88888 7/5/2010
What I need to do is pull the record for each unique ID where the DateConfirmed is the most recent. However, in some instances I have an ID that has more than one record with the same 'most recent' DateConfirmed. As a tie breaker in those situations, I'd like to go with the record that has the most fields populated. So in this example, the result I'm looking for would pull back:
12345 Bugs Bunny 123 Hello Street Topeka KS 22222 12/1/1985
54321 Elmer Fudd 678 Penny Lane Detroit MI 88888 7/5/2010
The catch is I have to use inline SQL from a VB6 app to do it. Any help would be appreciated.
ID FirstName LastName Address1 City State Zip DateConfirmed
12345 Bugs Bunny 123 Hello Street Topeka KS 22222 12/1/1985
12345 Bugs Bunny KS 22222 12/1/1985
12345 Bugs Bunny 555 What Lane Topeka KS 22222 1/1/1980
54321 Elmer Fudd 234 Looney Street Detriot MI 88888 11/5/2000
54321 Elmer Fudd 678 Penny Lane Detroit MI 88888 7/5/2010
What I need to do is pull the record for each unique ID where the DateConfirmed is the most recent. However, in some instances I have an ID that has more than one record with the same 'most recent' DateConfirmed. As a tie breaker in those situations, I'd like to go with the record that has the most fields populated. So in this example, the result I'm looking for would pull back:
12345 Bugs Bunny 123 Hello Street Topeka KS 22222 12/1/1985
54321 Elmer Fudd 678 Penny Lane Detroit MI 88888 7/5/2010
The catch is I have to use inline SQL from a VB6 app to do it. Any help would be appreciated.