Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 12 total
Thread Functions
Tue, Apr 3 2007 11:55 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Anyone using functions with EDB yet, and if so can you share some code.

Roy Lambert
Wed, Apr 4 2007 5:48 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Roy,

<< Anyone using functions with EDB yet, and if so can you share some code.
>>

Do you want just any old example, or something specific ?

--
Tim Young
Elevate Software
www.elevatesoft.com

Thu, Apr 5 2007 3:59 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Tim


Any old example should do. Basically something I can use to see what and how to write them since the manual in its 1.01b1 incarnation isn't massively outspoken on the topic Smiley


Roy Lambert
Thu, Apr 5 2007 12:50 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Roy,

<< Any old example should do. Basically something I can use to see what and
how to write them since the manual in its 1.01b1 incarnation isn't massively
outspoken on the topic Smiley>>

Well, there is an example in the manual for CREATE FUNCTION:

-- This function looks up the sales tax
-- rate for a given state and county

CREATE FUNCTION LookupSalesTaxRate(IN State CHAR(2), IN County VARCHAR)
RETURNS DECIMAL(20,2)
BEGIN
  DECLARE TempCursor CURSOR FOR stmt;
  DECLARE Result DECIMAL(20,2) DEFAULT 0;

  PREPARE stmt FROM 'SELECT * FROM SalesTaxes WHERE State = ? AND County =
?';

  OPEN TempCursor USING State, County;

  IF (ROWCOUNT(TempCursor) > 0) THEN
     FETCH FIRST FROM TempCursor (TaxRate) INTO Result;
  END IF;

  CLOSE TempCursor;

  RETURN Result;
END

It's basically the same as a stored procedure except that a function has a
RETURNS clause and a RETURN statement at the end of the function body.

--
Tim Young
Elevate Software
www.elevatesoft.com

Thu, Apr 5 2007 1:54 PMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Tim

>It's basically the same as a stored procedure except that a function has a
>RETURNS clause and a RETURN statement at the end of the function body.

No need to swear. I don't know what stored procedure's are either Smiley

Roy Lambert

ps didn't think to look under the CREATE part of the OLH
Fri, Apr 6 2007 10:50 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Tim


I think old pea brain needs a bit more help than that. What I'm trying to do is a simple thing I can do easily in SQL (I though that would give me a head start). Simply test for wether a transaction is in a specific month or not. The SQL is

select * from transactions where
extract(MONTH from _Date) = 4

What I wanted to do (as a training exercise) is replace it with an SQL function so I would type

select * from transactions where
IsInMonth(4,_Date)


Roy Lambert
Fri, Apr 6 2007 1:06 PMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Cracked it


CREATE FUNCTION "IsInMonth" (IN "cDate" DATE, IN "Comparator" INTEGER)
RETURNS BOOLEAN
BEGIN
RETURN ( EXTRACT(MONTH FROM cDate) = Comparator);
END


Roy Lambert
Fri, Apr 6 2007 1:06 PMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Tim


This doesn't work, and I don't understand why


CREATE FUNCTION "IsInMonth" (IN "cDate" DATE, IN "Comparator" INTEGER)
RETURNS BOOLEAN
BEGIN
IF
EXTRACT(MONTH FROM cDate) = Comparator
THEN
RETURN TRUE
ELSE
RETURN FALSE
END IF;
END


================================================================================
SQL Error (ElevateDB 1.02 Build 1)
================================================================================

ElevateDB Error #700 An error was found in the statement at line 7 and column 1
(Expected : but instead found RETURN)

Roy Lambert
Fri, Apr 6 2007 3:13 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Roy,

<< Cracked it >>

Yep, that looks good. Smiley

--
Tim Young
Elevate Software
www.elevatesoft.com

Fri, Apr 6 2007 3:13 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Roy,

<< No need to swear. I don't know what stored procedure's are either Smiley>>

Swear ? Smiley

--
Tim Young
Elevate Software
www.elevatesoft.com

Page 1 of 2Next Page »
Jump to Page:  1 2
Image