🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: temporal table for stored procedure

#895
From: Wayne Niddery [TeamB]
Date: Sat, 07 Apr 2007 17:31
43 lines
2676 bytes
aleplgr wrote:
>
> But the stored procedure needs the table to be ordered in a
> particular order.

The stored proc can select it with an Order By.

> SELECT * FROM TEMP1 ORDERED BY COL1  AS TEMP
> because my procedure needs the table ordered

The *physical* order of records in a table is never guaranteed in a 
relational SQL database (unless it specifically supports what are called 
"cluster" indexes, which InterBase does not support). So even though your 
select includes an Order By, the records will be inserted in whatever 
physical order is most convenient for the server. In order to see records in 
a particular order you must select them in that order *at the point where 
you want to view or process them*, not at the point of inserting them.

> I should order the table before starting to work with it in the
> procedure and I don't know how to ORDER it and give it a name..

You don't have to give it a name, you just need to select them in the order 
you want, so in the stored procedure you need to do this:

FOR
  SELECT FLD1, FLD2, FLD3 [,...] FROM TEMP1
  ORDER BY COL1
  INTO :FLD1, :FLD2, :FLD3 [,...]
DO BEGIN
  // do whatever processing you need here
END;

You need to define local variables for the fields, e.g. in the above sample, 
that might be:

DECLARE VARIABLE FLD1 INTEGER;
DECLARE VARIABLE FLD2 VARCHAR(20);
DECLARE VARIABLE FLD3 DATE;

-- 
Wayne Niddery - Winwright, Inc (www.winwright.ca)
"The two most abundant elements in the universe are hydrogen and
stupidity." - Harlan Ellison 
Technical Details
Message-ID: <4617d559$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feed.tweaknews.nl!217.73.144.44.MISMATCH!ecngs!feeder.ecngs.de!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <461651ac$1@newsgroups.borland.com> <46165aee$1@newsgroups.borland.com> <461765aa$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,ea63e4de71f1ac2a
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:  <461651ac$1@newsgroups.borland.com> <46165aee$1@newsgroups.borland.com> <461765aa$1@newsgroups.borland.com>
Subject: Re: temporal table for stored procedure
Date: Sat, 7 Apr 2007 13:31:04 -0400
Lines: 45
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: <4617d559$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1175967065 69.17.170.228 (7 Apr 2007 10:31:05 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feed.tweaknews.nl!217.73.144.44.MISMATCH!ecngs!feeder.ecngs.de!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail