Avatar of SBarrharo
SBarrharo

asked on 

Pivot tables in SQL

I am having trouble getting data to pivot in my results

I have three tables
a WIP table, a Staff table, and an Engagement table.
the wip table is timesheet detail and we're trying to a total of how many hours each staff worked on each engagement. i've written the following query which returns the data needed

SELECT   TOP 100     E.ClientName AS Client, E.ClientPartner AS Partner, sum(W.WIPHours) AS Hours, S.LastName
FROM            tblEngagement E RIGHT JOIN
                         tblTranWIP AS W ON E.ContIndex = W.ContIndex CROSS JOIN
                         Staff AS S
GROUP BY E.ClientName, S.LastName, E.clientPartner


Sample Data

WIPTable
staff    hours    engagement
joe        5            A
steve    10          A
joe        20          B


Desired result

engagement      Joe      Steve
A                          5            10
B                          20          0
SQL

Avatar of undefined
Last Comment
ste5an
ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SQL
SQL

SQL (Structured Query Language) is designed to be used in conjunction with relational database products as of a means of working with sets of data. SQL consists of data definition, data manipulation, and procedural elements. Its scope includes data insert, query, update and delete, schema creation and modification, and data access control.

61K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo