/ *9.      Write a SQL query to retrieve loan number, customer first name, customer last name,
 property address, and bankruptcy attorney name.  I want all the records that have the
 same attorney name to be together, then the customer last name in order from Z-A
 (ex.Customer last name of Wyatt comes before customer last name of Anderson)*/

 Select  LoanNumber,CustomerFname,CustomerLname,Propertyaddress,BankruptcyAttorneyName
 From Loan
 Group BY BankruptcyAttorneyName,LoanNumber,CustomerFname,CustomerLname,Propertyaddress
Order by
LTrim(Reverse(Left(Reverse(CustomerLname), CharIndex(' ', Reverse(CustomerLname))))) Desc,
CustomerLname Desc -- Fall-over for when there isn't a last name

Is it right comment?
Soumi ChakrabortyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dsackerContract ERP Admin/ConsultantCommented:
Since the last and first names are already separate, you probably don't need to reverse them or us any functions. And since you're not SUM'ing or doing any grouping functions, you don't need the GROUP BY, either. Ordering by the BankruptcyAttorneyName will group them in order:

SELECT  LoanNumber,
FROM    loan
ORDER BY BankruptcyAttorneyName,
         CustomerLname DESC,
         CustomerFname DESC,

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Deepak ChauhanSQL Server DBACommented:
Select  LoanNumber,CustomerFname,CustomerLname,Propertyaddress,BankruptcyAttorneyName
  From Loan
  Group BY BankruptcyAttorneyName,LoanNumber,CustomerFname,CustomerLname,Propertyaddress
 Order by  CustomerLname Desc 

Open in new window

Soumi ChakrabortyAuthor Commented:
I've requested that this question be deleted for the following reason:

dsackerContract ERP Admin/ConsultantCommented:
Question asked, question answered. Recommend splitting the points between me and Deepak (250 each) with a grade of A (each).
Soumi ChakrabortyAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.