Subject Re: How To: Write a Store Proc. for the following
Author Dorin Vasilescu
Hi
If yout teplates are translated to something that Firebird can
understand and evaluate, then you can use the new EXECUTE STATEMENT
Instead of:
'Bill no. ' + xrow.fld1 + ' Bill dt. ' + xrow.fld2 + 'so on'
chenge to this:
'Bill no. ' || fld1 || ' Bill dt. ' || fld2 || 'so on'

Try this procedure:

CREATE PROCEDURE MY_PROCEDURE (
TIID INTEGER,
TCFLAG CHAR(1))
RETURNS (
RETVAL VARCHAR(500))
AS
DECLARE VARIABLE M_NARRTEMPLATE VARCHAR(500);
begin
if (tcflag = 'X') then begin
select narrtemplate from narrmaster where n='XCHILDTEMPLATE'
into :m_narrtemplate ;
for execute statement
'select ' || :m_narrtemplate || ' from xchild where ipid =
' || :tiid
INTO :retval do begin
suspend;
end
end
if (tcflag = 'Y') then begin
end
end

--- In firebird-support@yahoogroups.com, Namit Nathwani
<namitnathwani@h...> wrote:
> Hi all
>
> I am pretty new to RDBMS's and come from a Visual FoxPro background. I
> would like to write a Stored Procedure that I can use the results in
Report
> Manager in such a manner:
>
> SELECT NarrationField FROM MY_STOREDPROCEDURE(:iID, :cFlag)
>
> I will be sending 2 parameters 1st will be the ID to which the
record has
> to belong and 2nd a Flag so that I can do a CASE statement in the
stored
> proc. to execute the related SELECT statement. The resulting cursor
I will
> then convert to a narration using another table meant to help generate
> narrations, something like this pseudo / FoxPro code:
>
> PARAMETERS tiID, tcFlag
>
> lcRetVal
>
> DO CASE
> CASE tcFlag = "X"
> SELECT xc.fld1, xc.fld2, xc.fld3 FROM xchild xc WHERE
> xc.iPID = tiID INTO CURSOR xrow
>
> SELECT n.NarrTemplate FROM NarrMaster n WHERE n =
> "XCHILDTEMPLATE" INTO CURSOR xnarr
>
> now xnarr.NarrTemplate will contain something like
this
> "'Bill no. ' + xrow.fld1 + ' Bill dt. ' + xrow.fld2 + 'so on'"
>
> lcRetVal = translated xnarr.NarrTemplate in VFP I
would
> assign it to a variable and macro substitute it.
>
> CASE tcFlag = "Y"
> ...
> ...
> OTHERWISE
> lcRetVal = "Unknown Flag can't create narrations"
> ENDCASE
>
> RETURN lcRetVal
>
>
> Hoping this is possible or another alternative to get it done.
>
> Please advise.
>
>
>
>
> Regards
> Bhavbhuti
> ___________________________________________
> Softwares for Indian Businesses at:
> http://venussoftop.tripod.com
> namitbn@p...
> ___________________________________________
>
> ----------
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.659 / Virus Database: 423 - Release Date: 15/04/2004
>
>
> [Non-text portions of this message have been removed]