1

I am using Microsoft SQL Server Management Studio 2008.

I have a Blood_Pressure_Systolic field and a Blood_Pressure_Diastolic field. I need to use these two fields to identify normal blood pressure, prehypertension, stage 1 hypertension, and stage 2 hypertension based on the Mayo Clinic's categories here: Mayo Clinic Blood Pressure Chart

I'm currently using the CASE expression below to filter the systolic ranges and the diastolic ranges for each category. However, if a person has a systolic blood pressure in a lower range and a diastolic blood pressure in a higher range, I want to return the higher range, and vice versa. For example, if John Smith has 125 systolic (prehypertension) and 95 diastolic (Stage 1 hypertension), then I want the field to return that he has Stage 1 hypertension.

CASE WHEN BP_Systolic < '120' AND BP_Diastolic < '80' THEN 'Normal'

WHEN BP_Systolic BETWEEN '120' AND '139' OR BP_Diastolic BETWEEN '80' AND '89' THEN 'Prehypertension'

WHEN BP_Systolic BETWEEN '140' AND '159' OR BP_Diastolic BETWEEN '90' AND '99' THEN 'Stage 1 Hypertension'

WHEN BP_Systolic >= '160' OR BP_Diastolic >= '100' THEN 'Stage 2 Hypertension'
END AS BP_Category
4

2 回答 2

2

我认为只需对CASE子句进行排序就可以了,因为它是按顺序解析的:

CASE 
    WHEN BP_Systolic >= '160' OR BP_Diastolic >= '100' THEN 'Stage 2 Hypertension'
    WHEN BP_Systolic BETWEEN '140' AND '159' OR BP_Diastolic BETWEEN '90' AND '99' THEN 'Stage 1 Hypertension'
    WHEN BP_Systolic BETWEEN '120' AND '139' OR BP_Diastolic BETWEEN '80' AND '89' THEN 'Prehypertension'
    WHEN BP_Systolic < '120' AND BP_Diastolic < '80' THEN 'Normal'
END AS BP_Category

虚拟小提琴试用:http ://sqlfiddle.com/#!3/8ad7f/3

于 2013-06-13T20:46:25.730 回答
0

case语句按顺序进行评估。因此,此语句优先考虑“正常”(尽管根据其定义,放置无关紧要)。要优先考虑其他事情,请颠倒顺序:

CASE WHEN BP_Systolic >= '160' OR BP_Diastolic >= '100'
     THEN 'Stage 2 Hypertension'
     WHEN BP_Systolic BETWEEN '140' AND '159' OR
           BP_Diastolic BETWEEN '90' AND '99'
     THEN 'Stage 1 Hypertension'
     WHEN BP_Systolic BETWEEN '120' AND '139' OR
          BP_Diastolic BETWEEN '80' AND '89'
     THEN 'Prehypertension'
     WHEN BP_Systolic < '120' AND BP_Diastolic < '80'
     THEN 'Normal'
END AS BP_Category
于 2013-06-13T20:47:49.413 回答