Case Statement Variable.

UDA
Enthusiast

Case Statement Variable.

Can a variable be used inside a case statement like so:

SELECT (CASE WHEN Year_id = :v_Year_id THEN 1 END)
FROM ......
2 REPLIES
Enthusiast

Re: Case Statement Variable.


You can use paramenter in macro,for example:

create macro testm(iday char(10)) as
(select case when date=:iday then 1 else 0 end;);

usage:
exec testm('2008-03-29');

Re: Case Statement Variable.

can variables be used with 'then' clause of case statement??

example:
select case when year='2011' and mon='jan' then :dayid
else -100 end as day_id_key from ..............