I have a current set of data that looks like the following:
Table Name: Project_EffectiveDating
| ProjectCode | RoleCode | EffectiveDate |
|---|---|---|
| 1a1 | A | 1/1/2020 |
| 1a1 | B | 1/1/2020 |
| 1a1 | C | 1/1/2020 |
| 1a1 | D | 1/1/2020 |
| 1a1 | E | 1/1/2020 |
| 1a1 | A | 2/1/2020 |
| ProjectCode | RoleCode | EffectiveDate |
|---|---|---|
| 1a1 | A | 1/1/2020 |
| 1a1 | B | 1/1/2020 |
| 1a1 | C | 1/1/2020 |
| 1a1 | D | 1/1/2020 |
| 1a1 | E | 1/1/2020 |
| 1a1 | A | 2/1/2020 |
| 1a1 | B | 2/1/2020 |
| 1a1 | C | 2/1/2020 |
| 1a1 | D | 2/1/2020 |
| 1a1 | E | 2/1/2020 |
Where the top table is existing data and the bottom table is the desired output.
I have been trying to join the table on itself with the following:
select
dbd.projectcode
, dbd.role
, dbd.effectivedate
from Project_EffectiveDating as dbd
left join Project_EffectiveDating as dad
on dad.projectcode = dbd.projectcode
and dbd.rolecode <> dad.rolecode
but obviously this is not working. I was thinking about doing a union statement using a WHERE NOT IN() but am at a loss. Any help would be appreciated.