I'm trying to extract data from the vJCJobRoles table which has the following columns:
- vJCJobRoles.Job (INT, not null, Key Field)
- vJCJobRoles.Role (CHAR, not null, Key Field)
- vJCJobRoles.VPUserName (CHAR, not null)
The vJCJobRoles table contains several Roles values for each Job and several VPUserName values for each Role. What I'm trying to do is create a View from this table that has one record per job and has the values in the Role field for each job as separate columns (field names) and has the VPUserName value in each Job record for each of the Row values. The result set shown below is giving me multiple records for some jobs in those cases where there is more than one value for the Role field. Notice I have no aggregating and therefore no Group By Clause.
The SQL code used and result set are shown below.
Thanks for your help.
...bob sutor
SQL CODE:
SELECT vjcjobroles.jcco,
vjcjobroles.job,
CASE
WHEN vjcjobroles.role = 'PM' THEN vjcjobroles.vpusername
end AS PMUserID,
CASE
WHEN vjcjobroles.role = 'SP' THEN vjcjobroles.vpusername
end AS SPUserID,
CASE
WHEN vjcjobroles.role = 'CPC' THEN vjcjobroles.vpusername
end AS CPCUserID,
CASE
WHEN vjcjobroles.role = 'PX' THEN vjcjobroles.vpusername
end AS PXUserID,
CASE
WHEN vjcjobroles.role = 'AA' THEN vjcjobroles.vpusername
end AS AAUserID,
CASE
WHEN vjcjobroles.role = 'APM' THEN vjcjobroles.vpusername
end AS ADMUserID
FROM vjcjobroles
This is the RESULT SET:
Bob Sutor