Home > Software engineering >  multiple conditions in oracle case with one :PAR
multiple conditions in oracle case with one :PAR

Time:02-05

I have a more complex query, but I will give a simple example. In SSRS same input but need different outputs:

select * from myTable where
case
when :PAR1 = 'hour' then myTable.hour = :PAR1
when :PAR1 = 'Mounth' then myTable.Mounth = :PAR1
end

How to make it?

I'm try to

case length(:PAR1)
when 18 then hour: = PAR1
..

always a mistake..

CodePudding user response:

You don't need a CASE expression here:

SELECT *
FROM myTable
WHERE (:PAR1 = 'hour' AND hour = :PAR1) OR
      (:PAR1 = 'Mounth' AND Mounth = :PAR1);

CodePudding user response:

Code you posted doesn't make sense to me; are you sure that :PAR1 is used everywhere? I'd expect something like this instead

select *
from mytable
where (:PAR1 = 'hour'   and hour   = :PAR2) 
   or (:PAR1 = 'Mounth' and mounth = :PAR2)
                                    -------
                        maybe not :PAR2, but 
                        certainly not :PAR1

Also, when you're dealing with hours, what is mounth? Shouldn't that be month?

  • Related