我只是想知道在MS SQL Server 2005中是否有办法将运算符作为存储过程参数传递。如果可能的话,我真的需要避免使用动态SQL。
@AppOperator = "AND"
WHERE (1 = 1) @AppOperator (2 = 2)
答案 0 :(得分:4)
不是你真正想要的东西(因为表达式必须重复),但这有效:
@AppOperator = "AND"
...
WHERE (
@AppOperator = "AND" AND ((1 = 1) AND (2 = 2))
OR
@AppOperator = "OR" AND ((1 = 1) OR (2 = 2))
)
...