Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread Function
Mon, Jun 1 2009 9:52 AMPermanent Link

Dieter Nagy
Hello,
please tell me if it possible to make a function without bindung to a table.

I will try this:

EXECUTE IMMEDIATE 'CREATE FUNCTION "Wochentag" (IN "IN" SMALLINT)
RETURNS VARCHAR(10) COLLATE ANSI
BEGIN   
DECLARE Result varchar;

CASE ...........
wHEN ..... THEN.....

I will give back the name of the weekday with this function.

Can anybody help me please.
TIA
Dieter NAgy
Mon, Jun 1 2009 11:45 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Dieter

Roy Lambert

Dieter Nagy <dieter.nagy@tele2.at> wrote on Mon, 1 Jun 2009 09:52:33 -0400

>Hello,
>please tell me if it possible to make a function without bindung to a table.

Sure can eg

FUNCTION "Demo" (IN "IN" SMALLINT)
RETURNS VARCHAR(10) COLLATE ANSI
BEGIN
RETURN 'Works';
END

Roy Lambert [Team Elevate]
Mon, Jun 1 2009 12:12 PMPermanent Link

Dieter Nagy
Roy,
thanks for your answer, but how can I handle this:

FUNCTION "Demo" (IN "IN" SMALLINT) <--------

My Input is for example  1 then I should get back 'Sunday'
                                   2 then I should get back 'Monday'    
                                   ...........

Thanks
Dieter Nagy
.












Roy Lambert wrote:

Dieter

Roy Lambert

Dieter Nagy <dieter.nagy@tele2.at> wrote on Mon, 1 Jun 2009 09:52:33 -0400

>Hello,
>please tell me if it possible to make a function without bindung to a table.

Sure can eg

FUNCTION "Demo" (IN "IN" SMALLINT)
RETURNS VARCHAR(10) COLLATE ANSI
BEGIN
RETURN 'Works';
END

Roy Lambert [Team Elevate]
Mon, Jun 1 2009 1:05 PMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Dieter

>My Input is for example 1 then I should get back 'Sunday'
> 2 then I should get back 'Monday'

That's a different question Smiley

FUNCTION "Demo" (IN "IN" SMALLINT)
RETURNS VARCHAR(10) COLLATE ANSI
BEGIN
DECLARE DoW VARCHAR;
CASE
WHEN IN = 1 THEN SET DoW = 'Monday';
WHEN IN = 2 THEN SET DoW = 'Tuesday';
WHEN IN = 3 THEN SET DoW = 'Wednesday';
WHEN IN = 4 THEN SET DoW = 'Thursday';
WHEN IN = 5 THEN SET DoW = 'Friday';
WHEN IN = 6 THEN SET DoW = 'Saturday';
WHEN IN = 7 THEN SET DoW = 'Sunday';
ELSE SET DoW = 'Unknown';
END CASE;
RETURN DoW;

I don't know if the integers represent the right days if EXTRACT(DAYOFWEEK..) is used

Roy Lambert [Team Elevate]


Mon, Jun 1 2009 11:42 PMPermanent Link

Dieter Nagy
Roy,

thanks for the answer.

Dieter Nagy





Roy Lambert wrote:

Dieter

>My Input is for example 1 then I should get back 'Sunday'
> 2 then I should get back 'Monday'

That's a different question Smiley

FUNCTION "Demo" (IN "IN" SMALLINT)
RETURNS VARCHAR(10) COLLATE ANSI
BEGIN
DECLARE DoW VARCHAR;
CASE
WHEN IN = 1 THEN SET DoW = 'Monday';
WHEN IN = 2 THEN SET DoW = 'Tuesday';
WHEN IN = 3 THEN SET DoW = 'Wednesday';
WHEN IN = 4 THEN SET DoW = 'Thursday';
WHEN IN = 5 THEN SET DoW = 'Friday';
WHEN IN = 6 THEN SET DoW = 'Saturday';
WHEN IN = 7 THEN SET DoW = 'Sunday';
ELSE SET DoW = 'Unknown';
END CASE;
RETURN DoW;

I don't know if the integers represent the right days if EXTRACT(DAYOFWEEK..) is used

Roy Lambert [Team Elevate]
Image