Article View: borland.public.interbase.sql
Article #11252Selective Returns for a stored procedure
From: Noel
Date: Fri, 29 Nov 2002 18:10
Date: Fri, 29 Nov 2002 18:10
41 lines
2893 bytes
2893 bytes
The procedure below is designed to return fields from a table 'L' under two conditions, depending on the input parameter 'EXCLUDE'. If exclude is 1 then the row is returned only if a
matching row in the ATTRIBUTE table is not present, and if zero, returns only if a matching row is present. I figured that could use IF/THEN statements and SUSPEND to return the data
selectively. However, despite the fact that I know the correct data is present, the SP does not return any results for the EXCLUDE=0 case, which leads me to suspect that output parameters
are not being set for every iteration of the loop.
The SELECT(*) COUNT FROM ATTRIBUTE statement uses values stored in the OUTPUT parameters. Are those values present regardless as to whether SUSPEND is called or not, or are they only set
when SUSPEND is called?
Can anyone shine any light on what might be going on here, or suggest an alternative approach?
Many thanks for your help.
CREATE PROCEDURE SAMPLE_QUERY QUERYVALUE VarChar(60) CHARACTER SET ISO8859_1, EXCLUDE Integer, ATTNAME VarChar(60) CHARACTER SET ISO8859_1) returns (LOCATION_ID Integer, LOCATION_NAME
VarChar(60) CHARACTER SET ISO8859_1, COUNTY_NAME VarChar(60) CHARACTER SET ISO8859_1, REGION_NAME VarChar(60) CHARACTER SET ISO8859_1) AS
DECLARE VARIABLE attid INTEGER;
DECLARE VARIABLE attcount INTEGER;
BEGIN
FOR SELECT LOCATION_ID, LNAME, CNAME, RNAME FROM L WHERE LNAME LIKE :QUERYVALUE
INTO :LOCATION_ID, :LOCATION_NAME, :COUNTY_NAME, :REGION_NAME DO
BEGIN
SELECT ATTRIBUTE_ID FROM ATTRIBUTELIST WHERE ATTRIBUTE = :ATTNAME INTO :attid;
SELECT COUNT(*) FROM ATTRIBUTE WHERE LOCATION_ID = :LOCATION_ID AND ATTRIBUTE_ID = :attid INTO :attcount;
IF (EXCLUDE = 1) THEN
BEGIN
IF (attcount = 0) THEN
BEGIN
SUSPEND;
END
END
ELSE
BEGIN
IF (attcount > 0) THEN
BEGIN
SUSPEND;
END
END
END
END
Technical Details
Message-ID:
<nqafuuokqrvh9hknvvj98rukbbn98b8tpj@4ax.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!news.uni-x.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 114a0e,740d47ae7f4a6f9e,start X-Google-Attributes: gid114a0e,public X-Google-ArrivalTime: 2002-11-29 10:15:31 PST From: Noel <zzzz@oisin.demon.co.uk> Newsgroups: borland.public.interbase.sql Subject: Selective Returns for a stored procedure Date: Fri, 29 Nov 2002 18:10:51 +0000 Message-ID: <nqafuuokqrvh9hknvvj98rukbbn98b8tpj@4ax.com> X-Newsreader: Forte Agent 1.92/32.572 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 158.152.17.61 X-Trace: newsgroups.borland.com 1038593638 158.152.17.61 (29 Nov 2002 10:13:58 -0800) Lines: 42 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!news.uni-x.net!newsgroups.borland.com!not-for-mail