-1
我需要根據訪問天數從表中提取記錄。如何通過更正下面的查詢來實現這一點?它有語法錯誤(s)。我知道這個語法是不正確的,但它會讓你知道我想達到什麼。有多個條件的案例陳述
DECLARE @PatientByDate INT
SET @PatientByDate = 30
SELECT * FROM Visits
WHERE
CASE
WHEN(@PatientByDate = 90) then DaysVisited > 90
WHEN(@PatientByDate = 60) then DaysVisited >= 60 AND DaysVisited < 90
WHEN(@PatientByDate = 30) then DaysVisited >= 30 AND DaysVisited < 60
WHEN(@PatientByDate = 25) then DaysVisited < 30
WHEN(@PatientByDate = 0) then -500 AND <= 5000000
END
檢查http://stackoverflow.com/questions/24254164/sql-case-when-and – MusicLovingIndianGirl
'CASE'是**不是**聲明 - 它是一個**表達式**(它可以返回各種可能之一值)。你**不能**從「CASE」返回「代碼塊」或條件 - 只有一個原子值。 –