【发布时间】:2013-10-06 02:50:45
【问题描述】:
我想根据存储过程输入构建自定义的 Where 条件,如果不为 null 则我将在语句中使用它们,否则我不会使用它们。
if @Vendor_Name is not null
begin
set @where += 'Upper(vendors.VENDOR_NAME) LIKE "%"+ UPPER(@Vendor_Name) +"%"'
end
else if @Entity is not null
begin
set @where += 'AND headers.ORG_ID = @Entity'
end
select * from table_name where @where
但我得到了这个错误
An expression of non-boolean type specified in a context where a condition is expected, near 'set'.
【问题讨论】:
标签: sql sql-server stored-procedures where-clause dynamic-sql