🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.interbase.sql
Article #809

Re: Syntax problem

#809
From: Wayne Niddery [TeamB]
Date: Thu, 10 May 2007 16:37
55 lines
2640 bytes
philhege wrote:
>
> CREATE PROCEDURE name
> AS
> DECLARE VARIABLE variable_name DATE ;
> BEGIN
> variable_name = EXTRACT(DAY FROM current_date) + 1 ;
> SELECT * FROM Mytable WHERE CAST(datetime AS DATE) < :variable_name ;
> END
>
> And am getting the following error:
> Token unknown - line 9, char 68
> ;

That's because, in the context of a stored procedure, the Select statement 
is incomplete. I assume you are expecting one or more rows to be returned 
from this procedure? The procedure must declare return variables, and the 
select statement must place values into those variables.

CREATE PROCEDURE name
returns (
  fld1 integer,
  fld2 varchar(10),
  fld3 <whatever ...>
)
AS
    [...]
 SELECT fldA, fldB, fldC FROM Mytable WHERE CAST(datetime AS DATE) < 
:variable_name
 INTO fld1, fld2, fld2;

That will return *ONE* row (and if the select results in more than one, an 
error).

If you need to allow for more than one row then it needs to be:

 FOR
    SELECT fldA, fldB, fldC FROM Mytable WHERE CAST(datetime AS DATE) < 
:variable_name
    INTO fld1, fld2, fld2
 DO BEGIN
    SUSPEND;
 END;

And the calling application needs to select from this procedure rather than 
simply executing it:

    select * from name;

-- 
Wayne Niddery - Winwright, Inc (www.winwright.ca)
"If there is any principle of the Constitution that more imperatively
calls for attachment than any other, it is the principle of free
thought - not free thought for those who agree with us, but freedom for
the thought that we hate." - Oliver Wendell Holmes 
Technical Details
Message-ID: <46434a66@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder3.cambrium.nl!feeder5.cambrium.nl!feed.tweaknews.nl!217.73.144.44.MISMATCH!ecngs!feeder.ecngs.de!news.germany.com!news.belwue.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <1178811432.614753.73230@e51g2000hsg.googlegroups.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,24b201d9e19c2a2b
X-Google-Attributes: gid114a0e,public
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "Wayne Niddery [TeamB]" <wniddery@chaffaci.on.ca>
From: "Wayne Niddery [TeamB]" <wniddery@chaffaci.on.ca>
Newsgroups: borland.public.interbase.sql
References: <1178811432.614753.73230@e51g2000hsg.googlegroups.com>
Subject: Re: Syntax problem
Date: Thu, 10 May 2007 12:37:58 -0400
Lines: 57
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3028
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 69.17.170.228
Message-ID: <46434a66@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1178815078 69.17.170.228 (10 May 2007 09:37:58 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder3.cambrium.nl!feeder5.cambrium.nl!feed.tweaknews.nl!217.73.144.44.MISMATCH!ecngs!feeder.ecngs.de!news.germany.com!news.belwue.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail