0
我有一個select語句,它根據已經爲「程序」,「觀察」或者「包含在存儲過程中的'條件'。我正在使用'程序','觀察'和'條件'作爲可選參數。 '程序','條件'和'觀察'都存儲在不同的表格中。目標是計算一段時間內具有「程序」,「觀察」或「條件」的患者數量的「分子」值。Where子句返回Count()的所有行和非特定行()
看起來如果同一個患者有多個'程序',多個'觀察'或多個'條件','計數'是派生所有這些,而不是針對特定的「分子」值存儲過程。
Parameter declarations:
@CareSite VARCHAR(1000), /* where visit occurs */
@AgeStart VARCHAR(10), /* starting age patient's age falls in */
@AgeEnd VARCHAR(10), /* ending age patient's age falls in */
@Gender VARCHAR(10), /* 'men' or 'women'
@Procedure_Numerator VARCHAR(1000)=null, /* procedure the visit is for */
@Condition_Numerator VARCHAR(1000)=null, /* condition the visit is for */
@Observation_Numerator VARCHAR(1000)=null /* observation the visit is for */
SELECT statement:
DECLARE @D1NumVal INT
SET @D1NumVal = (SELECT COUNT(*) AS Numerator
FROM SAS2SQL_DenominatorPersonTest DPT
JOIN SAS2SQL_DenominatorProcedureTest DPRT
ON DPRT.PersonID = DPT.PersonID
JOIN SAS2SQL_DenominatorConditionTest DCT
ON DCT.Person_ID = DPT.PersonID
JOIN SAS2SQL_DenominatorObservationsTest DOT
ON DOT.PersonID = DPT.PersonID
WHERE DPT.D1 = 1
AND DPT.Age >= @AgeStart AND DPT.Age <= @AgeEnd
AND (@Procedure_Numerator IS NOT NULL AND
DPT.CareSiteName = @CareSite AND DPT.Wave =
@Wave
AND DPT.Gender = @Gender AND
DPRT.ProcudureSourceValue =
@Procedure_Numerator)
OR (@Condition_Numerator IS NOT NULL AND
DPT.CareSiteName = @CareSite AND DPT.Wave =
@Wave
AND DPT.Gender = @Gender AND
DCT.X_Condition_Source_Desc =
@Condition_Numerator)
OR (@Observation_Numerator IS NOT NULL AND
DPT.CareSiteName = @CareSite AND DPT.Wave =
@Wave
AND DPT.Gender = @Gender AND
DOT.ObservationSourceValue =
@Observation_Numerator))
我使用「CASE何時」的做法,但試了一下我上面已經返回的結果更接近我試圖生成。
謝謝你的建議,dnoeth。它看起來像工作。我現在只看到包含每波適當計數的結果。訪問發生在每個wave的開始日期和結束日期之間,大概是3個月的時間。感謝您的幫助。 – M72
嗯......它看起來像在關於計數關閉的其他分子值進一步測試之後仍然存在問題。我今天會更加努力,看看我能否解決它... – M72