Decipher Sequel Query from MS SQL

Can someone tell me what this is doing?  Does the ca at the end mean that is the name of the stuff in ( )?  And what is the little b for?

 left outer join (
            select b.HSP_ACCOUNT_ID
            ,MAX(b.BALANCE) as BALANCE
            from (select hs.HSP_ACCOUNT_ID
                  ,BALANCE = hs.TOT_CHGS+hs.TOT_PMTS+hs.TOT_ADJS
                  from clarity.dbo.HSP_HAR_SNAPSHOT hs
                  where hs.COLL_AGENCY_ASSN_DT is not null and
                  hs.COLL_AGENCY_ASSN_DT >= @StartDate and
                  hs.COLL_AGENCY_ASSN_DT < DATEADD(d,1,@EndDate)) b
            group by b.HSP_ACCOUNT_ID
      )ca
            on HSP_ACCOUNT.HSP_ACCOUNT_ID = ca.HSP_ACCOUNT_ID
Becky EdwardsEpic Clarity DeveloperAsked:
Who is Participating?
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.

Thomas WheelerCommented:
Right it's the alias and is called with ca.column
0
Brian CroweDatabase AdministratorCommented:
"ca" is a dataset alias for the subquery beginning after "left outer join" in Line 1.

"b" is a table alias for the subquery beginning after "from" in Line 4.

This can probably be rewritten to be more readable using a common-table-expression.
0
Scott PletcherSenior DBACommented:
Or maybe just align it more consistently:


left outer join (
             select b.HSP_ACCOUNT_ID
             ,MAX(b.BALANCE) as BALANCE
             from (
                   select hs.HSP_ACCOUNT_ID
                   ,BALANCE = hs.TOT_CHGS+hs.TOT_PMTS+hs.TOT_ADJS
                   from clarity.dbo.HSP_HAR_SNAPSHOT hs
                   where hs.COLL_AGENCY_ASSN_DT is not null and
                   hs.COLL_AGENCY_ASSN_DT >= @StartDate and
                   hs.COLL_AGENCY_ASSN_DT < DATEADD(d,1,@EndDate)
             ) as b
             group by b.HSP_ACCOUNT_ID
) as ca
             on HSP_ACCOUNT.HSP_ACCOUNT_ID = ca.HSP_ACCOUNT_ID
0

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
Vitor MontalvãoMSSQL Senior EngineerCommented:
Becky, do you still need help with this question?
0
Becky EdwardsEpic Clarity DeveloperAuthor Commented:
I appreciate this help.  I needed both comments to truly understand so I gave both points.  They were equally good.  Thank you!
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.