Last active
December 15, 2015 10:39
-
-
Save ryanguill/5247157 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with typenames as ( | |
select | |
id | |
, 'event' kind | |
, eventname name | |
from events | |
union all | |
select | |
id | |
, 'materials' kind | |
, materialname name | |
from materials | |
union all | |
select | |
id | |
, 'physician' kind | |
, physicianname name | |
from physicians | |
-- repeat for all your different types | |
) | |
select | |
transactionHistory.transactionObjectTypeID | |
, objectType.objectType | |
, COALESCE(typenames.name,'default for when type name isnt known') typename | |
from | |
TransactionHistory | |
inner | |
join objectTypes | |
on transactionHistory.transactionObjecTypeID = objectTypes.objectID | |
left outer | |
join typenames | |
on objectTypes.objectID = typenames.id | |
and objectTypes.objectType = typenames.kind | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment