Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread newbie EDB FUNCTiON
Thu, May 19 2011 5:30 PMPermanent Link

Adam Brett

Orixa Systems

I am just feeling my way with functions & have a really simple one which returns NULL though I don't _think_ it should.

CREATE FUNCTION SeasonStartDate()
RESULT DATE
BEGIN
 DECLARE RESULT DATE DEFAULT CAST('2010-11-01' AS DATE);
END

... I just want to be able to put the function call "SeasonStartDate()" into my SQL statements so I don't have to write out CAST('2010-11-01' as Date) every time & so when the next season starts I only have to change things in 1 place.

However the above returns a null. Probably there is an easier way!

--

More samples of functions & how to use them (I have looked through the EDB samples, which are really helpful) would be great, if anyone can point me at any.
Fri, May 20 2011 2:10 AMPermanent Link

Ralf Bieber

EDV Dienstleistungen Ralf Bieber

Adam Brett wrote:

> I am just feeling my way with functions & have a really simple one
> which returns NULL though I don't think it should.
>
> CREATE FUNCTION SeasonStartDate()
> RESULT DATE
> BEGIN
>   DECLARE RESULT DATE DEFAULT CAST('2010-11-01' AS DATE);
> END
>

Adam,

use this:

CREATE FUNCTION SeasonStartDate() RETURNS DATE
BEGIN
 DECLARE RESULT DATE DEFAULT CAST('2010-11-01' AS DATE);    
 Return Result;
END


Ralf
Fri, May 20 2011 2:17 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Adam


Using RESULT lead you into thinking in Delphi terms where Result is the thing returned. Not so here -


ALTER FUNCTION "SeasonStartDate" ()
RETURNS DATE
BEGIN     
 DECLARE RESULT DATE DEFAULT CAST('2010-11-01' AS DATE);
 RETURN RESULT;
END



Roy Lambert
Image