if {condition1} = '0' begin if {condition2} = 'Yes' Begin Set @SQLQuery = @SQLQuery + ' AND ' end else begin Set @SQLQuery = @SQLQuery + ' AND ' end end
答案 0 :(得分:0)
正如@Pranav在评论中所述,您可以执行以下操作:
if {condition1} = '0'
Set @SQLQuery = @SQLQuery + ' AND ' +
CASE WHEN {condition2} = 'Yes' THEN <whatever cond2=Yes>
ELSE <whatever cond2<>Yes> END
答案 1 :(得分:0)
希望这有帮助,只需在运行此
之前为@SQLQuery分配任何或空值SELECT @SQLQuery+ = CASE WHEN CONDITION1='0' AND CONDITION2='Yes' THEN
' AND '
WHEN CONDITION1='0' THEN
' AND '
END