Re: newbie: Creating a function

From: "Thomas F(dot) O'Connell" <tfo(at)monsterlabs(dot)com>
To: phatcher(at)macys(dot)com
Subject: Re: newbie: Creating a function
Date: 2002-02-06 16:31:44
Message-ID: 3C615A70.1010000@monsterlabs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

it would end up looking something like the following:

create function OwnedGoods( varchar( 6 ), varchar( 2 ), int, int, int,
int, int, int ) returns int as '
DECLARE
GMM_ID alias for $1;
Div_ID alias for $2;
Loc1 alias for $3;
Loc2 alias for $4;
Loc3 alias for $5;
Loc120 alias for $6;
Loc15 alias for $7;
Cheshire alias for $8;
BEGIN
/*
* see http://developer.postgresql.org/docs/postgres/plpgsql.html
* for more info...
*/
END;
' language 'plpgsql';

-tfo

> Here's the definition in MS:
> '-----START
>
> CREATE Function OwnedGoods
> ( @GMM_ID varchar(6)
> , @Div_ID varchar(2)
> , @Loc1 int
> , @Loc2 int
> , @Loc3 int
> , @Loc120 int
> , @Loc15 int
> , @Cheshire int
> )
> Returns Int
> As
> Begin
> Declare @Total Int
> If @GMM_ID = '0001'
> BEGIN
> If @Div_id = '15' or @Div_id = '16' or @Div_id = '17' or @Div_id =
> '23'
> Set @Total = sum(@Loc120 + @Loc3 )
> Else
> Set @Total = sum(@Cheshire)
> END
> If @GMM_ID = '0002'
> BEGIN
> Set @Total = sum(@loc15 + @Loc3)
> END
> If @GMM_ID = '0006' or @GMM_ID = '0007'
> BEGIN
> Set @Total = sum(@Loc1 + @loc2 +(at)Cheshire)
> END
> If @GMM_ID = '0008'
> BEGIN
> If @Div_id = '99'
> Set @Total = sum(@Loc120 + @Loc3 )
> END
> If @GMM_ID = '0003' or @GMM_ID = '0005' or @GMM_ID = '0009' or @GMM_ID
> = '999'
> Begin
> Set @Total = sum(@Cheshire)
> END
> if @GMM_ID is null or @Div_id='00' --Assume if bad data is from
> Cheshire
> Begin
> Set @Total = sum(@Cheshire)
> END
>
> Return(@Total)
> End
> '----END
>
>
>

Browse pgsql-general by date

  From Date Subject
Next Message Justin Clift 2002-02-06 16:37:24 Re: 7.1.3 : copy from stdin is very slow!
Previous Message Doug McNaught 2002-02-06 16:16:06 Re: Commit , Rollback