I have a table that contains a field with ICD codes (death classification codes). I want to create another field that decodes the cause of death based on the ICD codes. Here are some of the codes I'm working with as reference:
Cancer: Anything that starts with the letter "C", and all codes "D00-D49"
Heart Disease: "I20-I52"
Diabetes: "E10-E14"
Accidents: Anything that starts with the letters "V" and "W", all codes "X00-X59"
Codes can be up to 4 characters long, so the codes for Heart Disease, for example, encompass I201, I313, etc.
Anyway, I created a query to add a field that decodes the cause of death that looks like this (CAUSE is the field with the ICD Code):
SELECT CAUSE,
IIf(Left([CAUSE],1) In ('C'),"Cancer",
IIf(Left([CAUSE],2) In ('D0','D1','D2','D3','D4'),"Cancer",
IIf(Left([CAUSE],3) In ('G30'),"Alzheimer's disease",
IIf(Left([CAUSE],2) In ('I2','I3','I4'),"Heart Disease",
IIf(Left([CAUSE],3) In ('I51','I52'),"Heart Disease",
IIf(Left([CAUSE],2) In ('I6'),"Cerebrovascular disease",
IIf(Left([CAUSE],3) In ('E10','E11','E12','E13','E14'),"Diabetes",
IIf(Left([CAUSE],3) In ('J09','J10','J11','J12'),"Influenza/Pneumonia",
IIf(Left([CAUSE],3) In ('J40','J41'), "Chronic Lower Respiratory Diseases",
IIf(Left([CAUSE],2) In ('X6','X7'),"Suicide",
IIf(Left([CAUSE],3) In ('X80','X81','X82','X83','X84'),"Suicide",
IIf(Left([CAUSE],1) In ('V','W'),"Accident",
IIf(Left([CAUSE],2) In ('X0','X1','X2','X3','X4','X5'),"Accident",
"Other"
)))))))))))))
AS SpecCause
FROM ALLDeaths;
This particular code works, but if I add another line, I get a "query expression too complex for expression" error. The same happened with the Switch function.
SELECT cause,
SWITCH(
cause LIKE 'C*', "Cancer",
cause = 'G30', "Alzheimer's Disease",
cause LIKE 'I2*', "Heart Disease",
cause LIKE 'I6*', "Cerebrovascular disease",
cause LIKE 'E10*', "Diabetes",
cause LIKE 'E11*', "Diabetes",
cause LIKE 'E12*', "Diabetes",
cause LIKE 'E13*', "Diabetes",
cause LIKE 'E14*', "Diabetes",
cause LIKE 'W*', "Accident"
)
AS SpecCause
FROM ALLDeaths;
The above code works, but if I add another line, I'll get the same "query too complex for expression" error. Is there an alternative I can use that allows me to decode all of the ICD values without a limit?