Subject | Re: [ib-support] Re: decode or case features |
---|---|
Author | Martin D. Berezaga |
Post date | 2003-01-03T21:55:19Z |
> > I need output different values based on other field. Someting likeCan I use the SP in a statement like this?
> > that
> >
> > select
> > decode(doc_type, 1, from_store, 2, to_store) store_number
> > from document
>
>Any reason you couldn't use a Stored Procedure's If Then Else
>features?
>
>Something like:
>
>Create Procedure My_Proc(MyParameter Integer)
> Returns ( Store_Number Integer )
> As
> Declare Variable MyType Integer;
> begin
> for Select Doc_Type from document
> where MyField = :MyParameter
> Into :MyType do
> begin
> If (MyType = 1) then
> Store_Number = From_Store;
> Else
> If (MyType = 2) then
> Store_Number = To_Store;
> end
> Suspend;
> end
>
>Then just call it with:
>Select * from My_Proc('SomeParameter')
>
>Nice thing about using a SP, if you ever add another type in this
>situaltion, you only have to change one thing, not a bunch of queries.
>
>HTH
>
>Scott.
SELECT CODE
, NAME
, SELECT * FROM MY_PROC(CODE) as RESULT
FROM TABLE
And a call like this another one?
SELECT CODE
, NAME
, SELECT STORE_NUMBER FROM MY_PROC(CODE) as RESULT
FROM TABLE
---------------------------
Martin D. Berezaga
mdberezaga@...
ICQ : 18537142
Porto Alegre - RS - Brasil
---------------------------