【发布时间】:2013-04-18 04:05:26
【问题描述】:
在我的存储过程中间,我有以下sn-p代码:
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
那我该怎么做呢?
这个 sn-p 在 from 语句中(从 table1 a join table2 b on a.id=b.id and case when..)
【问题讨论】:
-
猜测 SQL Server?如果是这样,不使用动态 SQL 就无法做到这一点 - 每个查询都根据它访问的表来固定。