目前,我有一个存储过程,需要一个字符串

@vari as varchar(30)
if @vari is null
    SELECT * FROM TABLE
else
    SELECT * FROM TABLE WHERE col = @vari
endif


有没有什么方法可以内联if语句,从而不仅仅因为1个参数就声明2个select?

最佳答案

SELECT * FROM TABLE WHERE (@vari is null or col = @vari)

08-08 08:14