問題
使用 Informix Case Statement in Where Clause
解決方法
Schema:
a table schema [id] , [b_id] , [b_ver](can be null)
b table schema [id] , [ver] , [description]
Condition:
if a.ver is null then don't join b.ver else join b.ver to get description
Answer:
select *
from a,b
where 1=1
and a.b_id=b.id
and
(
case when (a.b_ver
is not null)
then a.b_ver
else b.ver
end)
=b.ver
How to do it:
use case statement when [a.b_ver] is null then that condition become [b.ver] self,otherwise that [a.b_ver] join [b.ver]
沒有留言:
張貼留言