I am trying to create a table that has the following structure:
SSN,
ICD9
From a table with the following structure:
SSN,
ICD9_1,
ICD9_2,
...,
ICD9_8
The only way I can see accomplishing this now is by using a massive union statement:
SELECT
DISTINCT SSN, ICD9 FROM (
SELECT SSN, ICD9_1 AS ICD9 FROM FAC_TEST UNION
SELECT SSN, ICD9_2 AS ICD9 FROM FAC_TEST UNION
SELECT SSN, ICD9_3 AS ICD9 FROM FAC_TEST UNION
SELECT SSN, ICD9_4 AS ICD9 FROM FAC_TEST UNION
SELECT SSN, ICD9_5 AS ICD9 FROM FAC_TEST UNION
SELECT SSN, ICD9_6 AS ICD9 FROM FAC_TEST UNION
SELECT SSN, ICD9_7 AS ICD9 FROM FAC_TEST UNION
SELECT SSN, ICD9_8 AS ICD9 FROM FAC_TEST) AS TEST;
However the actual source table for this tasks is massive, and hitting it 8 times would generate some calls from the DBA's.
Any suggestions?
Thanks!
SSN,
ICD9
From a table with the following structure:
SSN,
ICD9_1,
ICD9_2,
...,
ICD9_8
The only way I can see accomplishing this now is by using a massive union statement:
SELECT
DISTINCT SSN, ICD9 FROM (
SELECT SSN, ICD9_1 AS ICD9 FROM FAC_TEST UNION
SELECT SSN, ICD9_2 AS ICD9 FROM FAC_TEST UNION
SELECT SSN, ICD9_3 AS ICD9 FROM FAC_TEST UNION
SELECT SSN, ICD9_4 AS ICD9 FROM FAC_TEST UNION
SELECT SSN, ICD9_5 AS ICD9 FROM FAC_TEST UNION
SELECT SSN, ICD9_6 AS ICD9 FROM FAC_TEST UNION
SELECT SSN, ICD9_7 AS ICD9 FROM FAC_TEST UNION
SELECT SSN, ICD9_8 AS ICD9 FROM FAC_TEST) AS TEST;
However the actual source table for this tasks is massive, and hitting it 8 times would generate some calls from the DBA's.
Any suggestions?
Thanks!