This is the first time I've used the PIVOT function in SQL Server. The query below gives me the desired result.
SELECT PATIENTACCOUNT, FACILITYID,  AS PRINCPL_DX,  AS SEC_DX1,  AS SEC_DX2,  AS SEC_DX3,  AS SEC_DX4
SELECT PATIENTACCOUNT, FACILITYID, ICD9DXSEQUENCE, ICD9DXCODE
FOR ICD9DXSEQUENCE IN (,,,,)
) AS PVT
I'm wondering if it's possible to join to another table to achieve the result in this example below.
I've been searching a while now and can't seem to find anything that gets me to where I want to go.
I want to join the T_ENCOUNTER_ICD9DX table to a T_ICD9DX_Codes table ON
ICD9DXCODE column to get the Description of the Codes.
My desired result would be display the columns like ...
PATIENTACCOUNT, FACILITYID,  AS PRINCPL_DX, Princ_dx_description,  AS SEC_DX1, Sec_dx1_description,...
I've attached a simple create table / insert values script.
Any help is appreciated.