Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

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

Avatar of giggul
giggul asked on
Microsoft SQL ServerOracle DatabaseMicrosoft SQL Server 2005
15 Comments1 Solution564 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!!
Avatar of Lee Wadwell
Lee WadwellFlag of Australia imageProject Architect

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

This problem has been solved!
Unlock 1 Answer and 15 Comments.
See Answers