我希望能够在WHERE
子句中创建一个案例表达式,该表达式将使用变量来确定要应用的条件:
declare @Classification VARCHAR(20)
set @Classification = 'Leaseup/Stabilized'
select *
from attributes a
where
if @Classification = 'Leaseup/Stabilized' then a.subgroup8 in ('Lease-up Communities', 'Stabilized
Communities')
if @Classification = 'Product Type' then a.subgroup6 in ('Freestanding AL/ALZ', 'Rental Continuums')
select a.*
from attributes a
where (@Classification = 'Leaseup/Stabilized' and a.subgroup8 in ('Lease-up Communities', 'Stabilized Communities'
) OR
(@Classification = 'Product Type' and a.subgroup6 in ('Freestanding AL/ALZ', 'Rental Continuums')
)