SQL預存程式 實作動態查詢條件



完整出處請參考國外神人此篇教學:
https://www.codeproject.com/Articles/21234/Implementing-Dynamic-WHERE-Clause-in-Static-SQL

重點程式碼:

在SQL預存程式中,使用動態where查詢條件實作
/*Basic Syntax: Simple CASE*/
CASE input_expression
WHEN (when_expression1 IS NOT NULL) THEN result_expression1
WHEN (when_expression2 IS NOT NULL) THEN result_expression2 
WHEN (when_expressionN IS NOT NULL) THEN result_expressionN 
ELSE else_result_expression 
END

/*Basic Syntax: Searched CASE*/
CASE WHEN (boolean_expression1 IS NOT NULL) THEN result_expression1 
WHEN (boolean_expression2 IS NOT NULL) THEN result_expression2 
WHEN (boolean_expressionN IS NOT NULL) THEN result_expressionN 
ELSE else_result_expression 
END

留言