troubleshooting Question

*** Need multi-part query using SQL RANK function - Tricky !!!!

Avatar of giggul
giggul asked on
Microsoft SQL ServerMicrosoft SQL Server 2005Oracle Database
15 Comments2 Solutions564 ViewsLast Modified:
Hello experts!  I'm new here and hope you can help.  This is a tricky problem I have:

I have a table of customers' phone numbers.  A customer can have multiple phone numbers and multiple phone types (home, work, mobile, etc)... and any combination of such (2 home numbers and 1 work number, etc).  They can designate which number is "preferred"... and each customer may have multiple preferred" numbers.  Each record has a create date.

My problem:
I need a single row returned for each customer with a single preferred phone number.  
-  If a customer has one preferred phone number, then we will use that one.  
-  If they have multiple preferred phone numbers, then we use the most recent created one.
-  If they have no preferred phone number(s) identfied, then we use the most recent created one.

I will upload a sample data file shortly (could not attach it directly to this post)


Thank you so much!!
ASKER CERTIFIED SOLUTION
Lee Wadwell
Project Architect

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 15 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 15 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros