T-SQL using PIVOT to display data

I need to create a join that displays EmployeeID and Rate based on the AttendantCount
Currently the Rate and AttendantCount are displayed as rows but I need to display the data horizontal.
I was told this could possibly be done using PIVOT in t-sql.
I have attached a screenshot of what the result should look like

The CommissionLevelDetail table contains CommissionLevelID, AttendantCount, Rate
The CommissionLevelAssignment table contains CommissionLevelID, EmployeeID

Screenshot of expected resultstbl_CommissionLevelAssignment.xlsxtbl_CommissionLevelDetail.xlsx
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.

Mark WillsTopic AdvisorCommented:
It looks as if the tables are joined via  CommissionlevelID

And assume the aggregation for the PIVOT is a SUM(RATE)

Given the above, can certainly do :
select Employeeid,isnull([1],0) as Group1 ,isnull([2],0) as Group2,isnull([3],0) as Group3,isnull([4],0) as Group4,isnull([5],0) as Group5,isnull([6],0) as Group6,isnull([7],0) as Group7,isnull([8],0) as Group8,isnull([9],0) as Group9,isnull([10],0) as Group10
( select A.Employeeid, D.Rate, D.AttendantCount
  from tbl_CommissionLevelAssignment A
  inner join tbl_CommissionLevelDetail D on A.CommissionlevelID = D.CommissionLevelID ) SRC
  (sum(rate) for AttendantCount in ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10])) pvt

Open in new window

And to help explain PIVOT, I have written articles - it does get into dynamic SQL, but the first part does explain the pivot.

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
swaggrKAuthor Commented:
Thanks Mark...this was very useful.
Mark WillsTopic AdvisorCommented:
My pleasure, and very pleased you found it useful :)
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
Pivot Tables

From novice to tech pro — start learning today.