Code debugging - short code (don't get scared) !! [message #546516] |
Wed, 07 March 2012 04:37 |
Maverick27
Messages: 84 Registered: October 2008
|
Member |
|
|
Can somebody pls tell me why the code below isn't compiling in a Formula Placeholder ?
function New_ItemFormula return Char is
begin
return(select case when DT_EFFECT_DATE >= '01-JAN-11' then 'New' else NULL end from mst_item);
end;
or should i use DECODE ? If so, what will it be ?
Basically, i want to tag all "NEW" prods. in the report using date comparison.
Thanks in advance.
Sorry Folks - i will re-post the SQL statment. Needs some more Where conditions.
[Updated on: Wed, 07 March 2012 04:49] Report message to a moderator
|
|
|
|
Re: Code debugging - short code (don't get scared) !! [message #546526 is a reply to message #546521] |
Wed, 07 March 2012 05:10 |
Maverick27
Messages: 84 Registered: October 2008
|
Member |
|
|
Thanks as ever Littlefoot. I have modified the SQL so that it returns a "single row" result, but i'm getting a compilation err. Something to do with syntax.
Err. message: Encountered the symbol "CASE".....
function New_ItemFormula return Char is
retval varchar2(20);
begin
SELECT CASE WHEN dt_effect_date >= to_date('01.01.2011', 'dd.mm.yyyy') THEN 'New'
ELSE null END
INTO retval
FROM mst_item
WHERE vc_comp_code = '01'
AND vc_item_code = :vc_item_code;
return (retval);
end;
|
|
|
Re: Code debugging - short code (don't get scared) !! [message #546528 is a reply to message #546526] |
Wed, 07 March 2012 05:20 |
|
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
When reporting an error, specify it! It has its code (whether it is ORA-xxxxx, REP-xxxx, whatever).
I asked you which Reports version you use, didn't I? If it doesn't support CASE, you'll need to rewrite it, somehow. If you go with DECODE, you'll have to use SIGN function with it and subtract DT_EFFECT_DATE and 01.01.2011. The result is number of days, so you'll decide what to return based on that. Something like
select decode(sign(dt_effect_date - to_date('01.01.2011', 'dd.mm.yyyy')), 1, 'New', null)
from ...
Finally, please, click here - it will take only a few seconds to see what it is about, but will make your future messages better.
|
|
|
|
|