if exists statement between a case when condition sql -
in middle of stored procedure, have following snippet of code:
case when l.codeleasestatuscode = '5' , priorleaseid null , l.leaid in(select col1 waitlisthousehold) '2' else l.codeleasestatuscode end
however, final condition, wherein have select table waitlisthousehold, has issue. not databases has table. want last condition included when table exists. i'm getting errors when try this:
case when l.codeleasestatuscode = '5' , priorleaseid null if exists(select * information_schema.tables table_name='waitlisthousehold') begin , l.leaid in(select col1 waitlisthousehold) end '2' else l.codeleasestatuscode end
so how do correctly?
this snippet inside statement(from table1 join table2 b on a.id=b.id , case when..)
you can have case when clause inside 1 check if table exist or not
case when l.codeleasestatuscode = '5' , priorleaseid null case when exists(select * information_schema.tables table_name='waitlisthousehold') case when l.leaid in(select col1 waitlisthousehold) '2' else l.codeleasestatuscode end else '2' end '2'end else l.codeleasestatuscode end
Comments
Post a Comment