在我的存储过程的中间,我有以下代码片段:
case
when l.codeleasestatuscode = '5' and priorleaseid is null
and l.leaid in(select col1 from Waitlisthousehold)
then '2'
else l.codeleasestatuscode
end
但是,我必须从 Waitlisthousehold 表中进行选择的最终条件存在问题。并非所有数据库都有该表。所以我希望在表存在时包含最后一个条件。但是当我尝试这样做时出现错误:
case
when l.codeleasestatuscode = '5' and priorleaseid is null
IF EXISTS(select * from information_schema.tables where table_name='WaitlistHousehold')
begin
and l.leaid in(select col1 from Waitlisthousehold)
end
then '2'
else l.codeleasestatuscode
end
那么我该如何正确地做到这一点呢?
此代码段位于 from 语句中(从 table1 a join table2 b on a.id=b.id and case when..)