我想將SQL查詢轉換爲SQL服務器中的過程,但我在IF語句中遇到問題。我如何在SQL存儲過程中使用IF語句
這是我想要實現的邏輯:
//If the patientStatus equals "all" there will be no condition
patientStatus.ToString() == "all" ? "" :
(
patientStatus.ToString() == "out"
? " AND CMS_ENCOUNTER.ENCOUNTER_END_TIME IS NOT NULL"
:" AND CMS_ENCOUNTER.ENCOUNTER_END_TIME IS NULL "
)
搜索有關如何在存儲過程IF語句中使用後,我想出了這一點,但它有錯誤:
IF(@PATIENT_STATUS != 'all')
BEGIN
if(@PATIENT_STATUS = 'out')
BEGIN
AND CMS_ENCOUNTER.ENCOUNTER_END_TIME IS NOT NULL
END
else
BEGIN
AND CMS_ENCOUNTER.ENCOUNTER_END_TIME IS NULL
END
END
什麼錯誤你好嗎 – Matt
@馬特, 'IF_'附近的語法錯誤,'CMS_ENCOUNTER'附近的語法不正確 –