我可以在where子句中使用if子句吗?

时间:2009-08-27 16:39:38

标签: filesystems

where 
     if prog.levelnumber = 2 then
         i.level = 2 ---> select only the persons with level = 2 
     if prog.numnivel=1 then
         i.level = 1 ---> select only the persons with level = 1

1 个答案:

答案 0 :(得分:2)

对我来说这看起来像SQL,所以我就这样回答......

使用case声明:

select fields
  from tablename
 where i.level = case prog.levelnumber
                   when 2 then 2
                   else
                     case prog.numnivel
                       when 1 then 1
                     end
                 end