Looking for a better way to implement this stored procedure. The issue is
that at the end of the procedure, when you try to drop the temp table after
you open the cursor, you get an error stating can't perform that action
because there's a pending operation on the temp table (the cursor reading it
I assume)
And if you close the cursor in order to be able to drop the temp table, you
destroy the result table.
If anyone can think of a better way to implement this procedure without the
need of a temp table, I'd appreciate any ideas.
Thanks in advance!
CREATE PROCEDURE AIM.GetRetrievalImageDetail (IN decAIMRetrievalID
DECIMAL(13,0))
------------------------------------------------------------------------
-- SQL Stored Procedure
-- Original Author Date: April 7, 2004
-- Author: Anthony
-- Returns Image detail information for an individual AIMRetrieval.
--
-- April 14, 2004:
-- Removed STATUS as a field being returned from the AIMRetrievedItem Table
-- Changed AvailableFlag from 'Y' and 'N' to 1 and 2 per Stephanie's code.
--
------------------------------------------------------------------------
LANGUAGE SQL
RESULT SETS 1
P1: BEGIN
DECLARE GLOBAL TEMPORARY TABLE RetrievedItem
(AIMRETRIEVEDITEMID DECIMAL(13,0),
ARCHIVERETRIEVALID DECIMAL(13, 0),
AIMDOCUMENTID VARCHAR(256),
ARCHIVEDOCUMENTID VARCHAR(124),
CAPTUREDATE DATE,
ROUTINGTRANSITNUMBER VARCHAR(9),
MICRACCOUNTNUMBER VARCHAR(24),
POSTINGACCOUNTNUMBER VARCHAR(24),
LOCATION VARCHAR(24),
SERIALNUMBER VARCHAR(20),
AMOUNT DECIMAL(13, 2),
ITEMTYPE VARCHAR(20),
SEQUENCENUMBER VARCHAR(24),
SORRYDOCINDICATOR VARCHAR(20),
APPLICATIONID VARCHAR(20),
CREDITDEBITFLAG VARCHAR(5),
IMAGELENGTH INTEGER,
AVAILABLEFLAG INTEGER
) WITH REPLACE;
BEGIN
DECLARE SELECT_HIGHLEVEL CURSOR WITH RETURN FOR
SELECT
AIM.AIMRETRIEVAL.DESCRIPTION, AIM.AIMRETRIEVAL.AIMRETRIEVALRECEIPT,
AIM.STATUS.STATUS
FROM
AIM.AIMRETRIEVAL,
AIM.STATUS
WHERE
AIM.AIMRETRIEVAL.STATUSID = AIM.STATUS.STATUSID
AND decAIMRetrievalID = AIM.AIMRetrieval.AIMRetrievalID;
DECLARE SELECT_CURSOR CURSOR WITH RETURN FOR
SELECT * FROM SESSION.RetrievedItem;
INSERT INTO SESSION.RetrievedItem
(
AIMRETRIEVEDITEMID ,
ARCHIVERETRIEVALID ,
AIMDOCUMENTID ,
ARCHIVEDOCUMENTID ,
CAPTUREDATE ,
ROUTINGTRANSITNUMBER ,
MICRACCOUNTNUMBER ,
POSTINGACCOUNTNUMBER ,
LOCATION ,
SERIALNUMBER ,
AMOUNT ,
ITEMTYPE ,
SEQUENCENUMBER ,
SORRYDOCINDICATOR ,
APPLICATIONID ,
CREDITDEBITFLAG ,
IMAGELENGTH
)
SELECT
AIM.AIMRETRIEVEDITEM.AIMRETRIEVEDITEMID,
AIM.ARCHIVERETRIEVAL.ARCHIVERETRIEVALID, AIM.AIMRETRIEVEDITEM.AIMDOCUMENTID,
AIM.AIMRETRIEVEDITEM.ARCHIVEDOCUMENTID, AIM.AIMRETRIEVEDITEM.CAPTUREDATE,
AIM.AIMRETRIEVEDITEM.ROUTINGTRANSITNUMBER,
AIM.AIMRETRIEVEDITEM.MICRACCOUNTNUMBER,
AIM.AIMRETRIEVEDITEM.POSTINGACCOUNTNUMBER,
AIM.AIMRETRIEVEDITEM.LOCATION, AIM.AIMRETRIEVEDITEM.SERIALNUMBER,
AIM.AIMRETRIEVEDITEM.AMOUNT, AIM.AIMRETRIEVEDITEM.ITEMTYPE,
AIM.AIMRETRIEVEDITEM.SEQUENCENUMBER, AIM.AIMRETRIEVEDITEM.SORRYDOCINDICATOR,
AIM.AIMRETRIEVEDITEM.APPLICATIONID,
AIM.AIMRETRIEVEDITEM.CREDITDEBITFLAG,
Length(AIM.AIMRETRIEVEDITEM.ImageFront)
FROM
AIM.AIMRETRIEVAL,
AIM.STATUS,
AIM.AIMRETRIEVEDITEM,
AIM.ARCHIVERETRIEVAL,
AIM.ARCHIVETYPE
WHERE
AIM.AIMRETRIEVAL.STATUSID = AIM.STATUS.STATUSID
AND AIM.ARCHIVERETRIEVAL.ARCHIVERETRIEVALID =
AIM.AIMRETRIEVEDITEM.ARCHIVERETRIEVALID
AND AIM.AIMRETRIEVAL.AIMRETRIEVALID = AIM.ARCHIVERETRIEVAL.AIMRETRIEVALID
AND AIM.ARCHIVERETRIEVAL.ARCHIVEID = AIM.ARCHIVETYPE.ARCHIVEID
AND AIM.ARCHIVETYPE.ARCHIVETYPE = 'D'
AND AIM.AIMRETRIEVAL.AIMRETRIEVALID = decAIMRetrievalID;
UPDATE SESSION.RetrievedItem SET AVAILABLEFLAG = 2 WHERE
SESSION.RetrievedItem.ImageLength IS NULL OR
SESSION.RetrievedItem.ImageLength = 0;
UPDATE SESSION.RetrievedItem SET AVAILABLEFLAG = 1 WHERE
SESSION.RetrievedItem.ImageLength IS NOT NULL OR
SESSION.RetrievedItem.ImageLength > 0;
OPEN SELECT_HIGHLEVEL;
OPEN SELECT_CURSOR;
--CLOSE SELECT_CURSOR;
--DROP TABLE SESSION.RetrievedItem;
--CLOSE SELECT_HIGHLEVEL;
--CLOSE SELECT_CURSOR;
--BEGIN
--DROP TABLE SESSION.RetrievedItem;
--END;
END;
END P1
__________________
Anthony Robinson 2 3219
Anthony Robinison wrote: Looking for a better way to implement this stored procedure. The issue is that at the end of the procedure, when you try to drop the temp table after you open the cursor, you get an error stating can't perform that action because there's a pending operation on the temp table (the cursor reading it I assume)
And if you close the cursor in order to be able to drop the temp table, you destroy the result table.
If anyone can think of a better way to implement this procedure without the need of a temp table, I'd appreciate any ideas.
Thanks in advance!
CREATE PROCEDURE AIM.GetRetrievalImageDetail (IN decAIMRetrievalID DECIMAL(13,0)) ------------------------------------------------------------------------ -- SQL Stored Procedure -- Original Author Date: April 7, 2004 -- Author: Anthony -- Returns Image detail information for an individual AIMRetrieval. -- -- April 14, 2004: -- Removed STATUS as a field being returned from the AIMRetrievedItem Table -- Changed AvailableFlag from 'Y' and 'N' to 1 and 2 per Stephanie's code. -- ------------------------------------------------------------------------ LANGUAGE SQL RESULT SETS 1 P1: BEGIN
DECLARE GLOBAL TEMPORARY TABLE RetrievedItem (AIMRETRIEVEDITEMID DECIMAL(13,0), ARCHIVERETRIEVALID DECIMAL(13, 0), AIMDOCUMENTID VARCHAR(256), ARCHIVEDOCUMENTID VARCHAR(124), CAPTUREDATE DATE, ROUTINGTRANSITNUMBER VARCHAR(9), MICRACCOUNTNUMBER VARCHAR(24), POSTINGACCOUNTNUMBER VARCHAR(24), LOCATION VARCHAR(24), SERIALNUMBER VARCHAR(20), AMOUNT DECIMAL(13, 2), ITEMTYPE VARCHAR(20), SEQUENCENUMBER VARCHAR(24), SORRYDOCINDICATOR VARCHAR(20), APPLICATIONID VARCHAR(20), CREDITDEBITFLAG VARCHAR(5), IMAGELENGTH INTEGER, AVAILABLEFLAG INTEGER ) WITH REPLACE;
BEGIN DECLARE SELECT_HIGHLEVEL CURSOR WITH RETURN FOR SELECT AIM.AIMRETRIEVAL.DESCRIPTION, AIM.AIMRETRIEVAL.AIMRETRIEVALRECEIPT, AIM.STATUS.STATUS FROM AIM.AIMRETRIEVAL, AIM.STATUS WHERE AIM.AIMRETRIEVAL.STATUSID = AIM.STATUS.STATUSID AND decAIMRetrievalID = AIM.AIMRetrieval.AIMRetrievalID;
DECLARE SELECT_CURSOR CURSOR WITH RETURN FOR SELECT * FROM SESSION.RetrievedItem;
INSERT INTO SESSION.RetrievedItem ( AIMRETRIEVEDITEMID , ARCHIVERETRIEVALID , AIMDOCUMENTID , ARCHIVEDOCUMENTID , CAPTUREDATE , ROUTINGTRANSITNUMBER , MICRACCOUNTNUMBER , POSTINGACCOUNTNUMBER , LOCATION , SERIALNUMBER , AMOUNT , ITEMTYPE , SEQUENCENUMBER , SORRYDOCINDICATOR , APPLICATIONID , CREDITDEBITFLAG , IMAGELENGTH ) SELECT
AIM.AIMRETRIEVEDITEM.AIMRETRIEVEDITEMID, AIM.ARCHIVERETRIEVAL.ARCHIVERETRIEVALID, AIM.AIMRETRIEVEDITEM.AIMDOCUMENTID, AIM.AIMRETRIEVEDITEM.ARCHIVEDOCUMENTID, AIM.AIMRETRIEVEDITEM.CAPTUREDATE, AIM.AIMRETRIEVEDITEM.ROUTINGTRANSITNUMBER, AIM.AIMRETRIEVEDITEM.MICRACCOUNTNUMBER, AIM.AIMRETRIEVEDITEM.POSTINGACCOUNTNUMBER, AIM.AIMRETRIEVEDITEM.LOCATION, AIM.AIMRETRIEVEDITEM.SERIALNUMBER, AIM.AIMRETRIEVEDITEM.AMOUNT, AIM.AIMRETRIEVEDITEM.ITEMTYPE, AIM.AIMRETRIEVEDITEM.SEQUENCENUMBER, AIM.AIMRETRIEVEDITEM.SORRYDOCINDICATOR, AIM.AIMRETRIEVEDITEM.APPLICATIONID, AIM.AIMRETRIEVEDITEM.CREDITDEBITFLAG, Length(AIM.AIMRETRIEVEDITEM.ImageFront) FROM AIM.AIMRETRIEVAL, AIM.STATUS, AIM.AIMRETRIEVEDITEM, AIM.ARCHIVERETRIEVAL, AIM.ARCHIVETYPE WHERE AIM.AIMRETRIEVAL.STATUSID = AIM.STATUS.STATUSID AND AIM.ARCHIVERETRIEVAL.ARCHIVERETRIEVALID = AIM.AIMRETRIEVEDITEM.ARCHIVERETRIEVALID AND AIM.AIMRETRIEVAL.AIMRETRIEVALID = AIM.ARCHIVERETRIEVAL.AIMRETRIEVALID AND AIM.ARCHIVERETRIEVAL.ARCHIVEID = AIM.ARCHIVETYPE.ARCHIVEID AND AIM.ARCHIVETYPE.ARCHIVETYPE = 'D' AND AIM.AIMRETRIEVAL.AIMRETRIEVALID = decAIMRetrievalID;
UPDATE SESSION.RetrievedItem SET AVAILABLEFLAG = 2 WHERE SESSION.RetrievedItem.ImageLength IS NULL OR SESSION.RetrievedItem.ImageLength = 0; UPDATE SESSION.RetrievedItem SET AVAILABLEFLAG = 1 WHERE SESSION.RetrievedItem.ImageLength IS NOT NULL OR SESSION.RetrievedItem.ImageLength > 0;
That doesn't make a lot of sense to me. Assuming that ImageLength is 0, you
will set the AVAILABLEFLAG to 2 in the first query (= 0) and change it
right away to 1 in the second query (IS NOT NULL). Did you meant to
use ... AND ... in the 2nd query?
OPEN SELECT_HIGHLEVEL; OPEN SELECT_CURSOR; --CLOSE SELECT_CURSOR; --DROP TABLE SESSION.RetrievedItem; --CLOSE SELECT_HIGHLEVEL; --CLOSE SELECT_CURSOR; --BEGIN --DROP TABLE SESSION.RetrievedItem; --END; END; END P1
If I got this right, then the main logic of your procedure is this:
(1) declare temp table
(2) copy data from 5-way join to temp table
(3) change some data in the temp table
(4) open 1 cursor (SELECT_HIGHLEVEL) that queries the static tables
(5) open 1 cursor (SELECT_CURSOR) that queries the temp table
First, we can ignore step (4) because the temp table isn't needed there.
Next, you can combine (2), (3), and (5) into a single operation and, thus,
avoiding the temp table completely. This would be something like that:
DECLARE select_cursor CURSOR WITH RETURN FOR
SELECT AIM.AIMRETRIEVEDITEM.AIMRETRIEVEDITEMID,
AIM.ARCHIVERETRIEVAL.ARCHIVERETRIEVALID,
AIM.AIMRETRIEVEDITEM.AIMDOCUMENTID,
AIM.AIMRETRIEVEDITEM.ARCHIVEDOCUMENTID,
AIM.AIMRETRIEVEDITEM.CAPTUREDATE,
AIM.AIMRETRIEVEDITEM.ROUTINGTRANSITNUMBER,
AIM.AIMRETRIEVEDITEM.MICRACCOUNTNUMBER,
AIM.AIMRETRIEVEDITEM.POSTINGACCOUNTNUMBER,
AIM.AIMRETRIEVEDITEM.LOCATION,
AIM.AIMRETRIEVEDITEM.SERIALNUMBER,
AIM.AIMRETRIEVEDITEM.AMOUNT,
AIM.AIMRETRIEVEDITEM.ITEMTYPE,
AIM.AIMRETRIEVEDITEM.SEQUENCENUMBER,
AIM.AIMRETRIEVEDITEM.SORRYDOCINDICATOR,
AIM.AIMRETRIEVEDITEM.APPLICATIONID,
AIM.AIMRETRIEVEDITEM.CREDITDEBITFLAG,
Length(AIM.AIMRETRIEVEDITEM.ImageFront),
-- generate the "AVAILABLE_FLAG" on the fly
CASE
WHEN COALESCE(Length(AIM.AIMRETRIEVEDITEM.ImageFront), 0) = 0
THEN 2
ELSE 1
END
FROM AIM.AIMRETRIEVAL,
AIM.STATUS,
AIM.AIMRETRIEVEDITEM,
AIM.ARCHIVERETRIEVAL,
AIM.ARCHIVETYPE
WHERE AIM.AIMRETRIEVAL.STATUSID = AIM.STATUS.STATUSID AND
AIM.ARCHIVERETRIEVAL.ARCHIVERETRIEVALID =
AIM.AIMRETRIEVEDITEM.ARCHIVERETRIEVALID AND
AIM.AIMRETRIEVAL.AIMRETRIEVALID =
AIM.ARCHIVERETRIEVAL.AIMRETRIEVALID AND
AIM.ARCHIVERETRIEVAL.ARCHIVEID = AIM.ARCHIVETYPE.ARCHIVEID AND
AIM.ARCHIVETYPE.ARCHIVETYPE = 'D' AND
AIM.AIMRETRIEVAL.AIMRETRIEVALID = decAIMRetrievalID;
In the above query, I packed the calculation of the AVAILABLE_FLAG in a CASE
expression. That way, you could save at least the 2nd UPDATE operation,
but here we don't need any UPDATE at all.
The COALESCE function returns the first argument that is not NULL. So if
LENGTH(...) returns NULL, then the '0' is used and the AVAILABLE_FLAG is
set to 2. If LENGTH is already 0, then the flag is also set to 2. That
covers both conditions from the 1st update. Consequentially, the ELSE
branch (setting the flag to 1) is only taken if LENGTH is not NULL and if
it is larger than 0. (I assume that my comment on the 2 UPDATE statements
above regarding the conditions was correct...)
--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Anthony Robinison wrote: Looking for a better way to implement this stored procedure. The issue is that at the end of the procedure, when you try to drop the temp table after you open the cursor, you get an error stating can't perform that action because there's a pending operation on the temp table (the cursor reading it I assume)
And if you close the cursor in order to be able to drop the temp table, you destroy the result table.
If anyone can think of a better way to implement this procedure without the need of a temp table, I'd appreciate any ideas.
Thanks in advance!
CREATE PROCEDURE AIM.GetRetrievalImageDetail (IN decAIMRetrievalID DECIMAL(13,0)) ------------------------------------------------------------------------ -- SQL Stored Procedure -- Original Author Date: April 7, 2004 -- Author: Anthony -- Returns Image detail information for an individual AIMRetrieval. -- -- April 14, 2004: -- Removed STATUS as a field being returned from the AIMRetrievedItem Table -- Changed AvailableFlag from 'Y' and 'N' to 1 and 2 per Stephanie's code. -- ------------------------------------------------------------------------ LANGUAGE SQL RESULT SETS 1 P1: BEGIN
DECLARE GLOBAL TEMPORARY TABLE RetrievedItem (AIMRETRIEVEDITEMID DECIMAL(13,0), ARCHIVERETRIEVALID DECIMAL(13, 0), AIMDOCUMENTID VARCHAR(256), ARCHIVEDOCUMENTID VARCHAR(124), CAPTUREDATE DATE, ROUTINGTRANSITNUMBER VARCHAR(9), MICRACCOUNTNUMBER VARCHAR(24), POSTINGACCOUNTNUMBER VARCHAR(24), LOCATION VARCHAR(24), SERIALNUMBER VARCHAR(20), AMOUNT DECIMAL(13, 2), ITEMTYPE VARCHAR(20), SEQUENCENUMBER VARCHAR(24), SORRYDOCINDICATOR VARCHAR(20), APPLICATIONID VARCHAR(20), CREDITDEBITFLAG VARCHAR(5), IMAGELENGTH INTEGER, AVAILABLEFLAG INTEGER ) WITH REPLACE;
BEGIN DECLARE SELECT_HIGHLEVEL CURSOR WITH RETURN FOR SELECT AIM.AIMRETRIEVAL.DESCRIPTION, AIM.AIMRETRIEVAL.AIMRETRIEVALRECEIPT, AIM.STATUS.STATUS FROM AIM.AIMRETRIEVAL, AIM.STATUS WHERE AIM.AIMRETRIEVAL.STATUSID = AIM.STATUS.STATUSID AND decAIMRetrievalID = AIM.AIMRetrieval.AIMRetrievalID;
DECLARE SELECT_CURSOR CURSOR WITH RETURN FOR SELECT * FROM SESSION.RetrievedItem;
INSERT INTO SESSION.RetrievedItem ( AIMRETRIEVEDITEMID , ARCHIVERETRIEVALID , AIMDOCUMENTID , ARCHIVEDOCUMENTID , CAPTUREDATE , ROUTINGTRANSITNUMBER , MICRACCOUNTNUMBER , POSTINGACCOUNTNUMBER , LOCATION , SERIALNUMBER , AMOUNT , ITEMTYPE , SEQUENCENUMBER , SORRYDOCINDICATOR , APPLICATIONID , CREDITDEBITFLAG , IMAGELENGTH ) SELECT
AIM.AIMRETRIEVEDITEM.AIMRETRIEVEDITEMID, AIM.ARCHIVERETRIEVAL.ARCHIVERETRIEVALID, AIM.AIMRETRIEVEDITEM.AIMDOCUMENTID, AIM.AIMRETRIEVEDITEM.ARCHIVEDOCUMENTID, AIM.AIMRETRIEVEDITEM.CAPTUREDATE, AIM.AIMRETRIEVEDITEM.ROUTINGTRANSITNUMBER, AIM.AIMRETRIEVEDITEM.MICRACCOUNTNUMBER, AIM.AIMRETRIEVEDITEM.POSTINGACCOUNTNUMBER, AIM.AIMRETRIEVEDITEM.LOCATION, AIM.AIMRETRIEVEDITEM.SERIALNUMBER, AIM.AIMRETRIEVEDITEM.AMOUNT, AIM.AIMRETRIEVEDITEM.ITEMTYPE, AIM.AIMRETRIEVEDITEM.SEQUENCENUMBER, AIM.AIMRETRIEVEDITEM.SORRYDOCINDICATOR, AIM.AIMRETRIEVEDITEM.APPLICATIONID, AIM.AIMRETRIEVEDITEM.CREDITDEBITFLAG, Length(AIM.AIMRETRIEVEDITEM.ImageFront) FROM AIM.AIMRETRIEVAL, AIM.STATUS, AIM.AIMRETRIEVEDITEM, AIM.ARCHIVERETRIEVAL, AIM.ARCHIVETYPE WHERE AIM.AIMRETRIEVAL.STATUSID = AIM.STATUS.STATUSID AND AIM.ARCHIVERETRIEVAL.ARCHIVERETRIEVALID = AIM.AIMRETRIEVEDITEM.ARCHIVERETRIEVALID AND AIM.AIMRETRIEVAL.AIMRETRIEVALID = AIM.ARCHIVERETRIEVAL.AIMRETRIEVALID AND AIM.ARCHIVERETRIEVAL.ARCHIVEID = AIM.ARCHIVETYPE.ARCHIVEID AND AIM.ARCHIVETYPE.ARCHIVETYPE = 'D' AND AIM.AIMRETRIEVAL.AIMRETRIEVALID = decAIMRetrievalID;
UPDATE SESSION.RetrievedItem SET AVAILABLEFLAG = 2 WHERE SESSION.RetrievedItem.ImageLength IS NULL OR SESSION.RetrievedItem.ImageLength = 0; UPDATE SESSION.RetrievedItem SET AVAILABLEFLAG = 1 WHERE SESSION.RetrievedItem.ImageLength IS NOT NULL OR SESSION.RetrievedItem.ImageLength > 0;
That doesn't make a lot of sense to me. Assuming that ImageLength is 0, you
will set the AVAILABLEFLAG to 2 in the first query (= 0) and change it
right away to 1 in the second query (IS NOT NULL). Did you meant to
use ... AND ... in the 2nd query?
OPEN SELECT_HIGHLEVEL; OPEN SELECT_CURSOR; --CLOSE SELECT_CURSOR; --DROP TABLE SESSION.RetrievedItem; --CLOSE SELECT_HIGHLEVEL; --CLOSE SELECT_CURSOR; --BEGIN --DROP TABLE SESSION.RetrievedItem; --END; END; END P1
If I got this right, then the main logic of your procedure is this:
(1) declare temp table
(2) copy data from 5-way join to temp table
(3) change some data in the temp table
(4) open 1 cursor (SELECT_HIGHLEVEL) that queries the static tables
(5) open 1 cursor (SELECT_CURSOR) that queries the temp table
First, we can ignore step (4) because the temp table isn't needed there.
Next, you can combine (2), (3), and (5) into a single operation and, thus,
avoiding the temp table completely. This would be something like that:
DECLARE select_cursor CURSOR WITH RETURN FOR
SELECT AIM.AIMRETRIEVEDITEM.AIMRETRIEVEDITEMID,
AIM.ARCHIVERETRIEVAL.ARCHIVERETRIEVALID,
AIM.AIMRETRIEVEDITEM.AIMDOCUMENTID,
AIM.AIMRETRIEVEDITEM.ARCHIVEDOCUMENTID,
AIM.AIMRETRIEVEDITEM.CAPTUREDATE,
AIM.AIMRETRIEVEDITEM.ROUTINGTRANSITNUMBER,
AIM.AIMRETRIEVEDITEM.MICRACCOUNTNUMBER,
AIM.AIMRETRIEVEDITEM.POSTINGACCOUNTNUMBER,
AIM.AIMRETRIEVEDITEM.LOCATION,
AIM.AIMRETRIEVEDITEM.SERIALNUMBER,
AIM.AIMRETRIEVEDITEM.AMOUNT,
AIM.AIMRETRIEVEDITEM.ITEMTYPE,
AIM.AIMRETRIEVEDITEM.SEQUENCENUMBER,
AIM.AIMRETRIEVEDITEM.SORRYDOCINDICATOR,
AIM.AIMRETRIEVEDITEM.APPLICATIONID,
AIM.AIMRETRIEVEDITEM.CREDITDEBITFLAG,
Length(AIM.AIMRETRIEVEDITEM.ImageFront),
-- generate the "AVAILABLE_FLAG" on the fly
CASE
WHEN COALESCE(Length(AIM.AIMRETRIEVEDITEM.ImageFront), 0) = 0
THEN 2
ELSE 1
END
FROM AIM.AIMRETRIEVAL,
AIM.STATUS,
AIM.AIMRETRIEVEDITEM,
AIM.ARCHIVERETRIEVAL,
AIM.ARCHIVETYPE
WHERE AIM.AIMRETRIEVAL.STATUSID = AIM.STATUS.STATUSID AND
AIM.ARCHIVERETRIEVAL.ARCHIVERETRIEVALID =
AIM.AIMRETRIEVEDITEM.ARCHIVERETRIEVALID AND
AIM.AIMRETRIEVAL.AIMRETRIEVALID =
AIM.ARCHIVERETRIEVAL.AIMRETRIEVALID AND
AIM.ARCHIVERETRIEVAL.ARCHIVEID = AIM.ARCHIVETYPE.ARCHIVEID AND
AIM.ARCHIVETYPE.ARCHIVETYPE = 'D' AND
AIM.AIMRETRIEVAL.AIMRETRIEVALID = decAIMRetrievalID;
In the above query, I packed the calculation of the AVAILABLE_FLAG in a CASE
expression. That way, you could save at least the 2nd UPDATE operation,
but here we don't need any UPDATE at all.
The COALESCE function returns the first argument that is not NULL. So if
LENGTH(...) returns NULL, then the '0' is used and the AVAILABLE_FLAG is
set to 2. If LENGTH is already 0, then the flag is also set to 2. That
covers both conditions from the 1st update. Consequentially, the ELSE
branch (setting the flag to 1) is only taken if LENGTH is not NULL and if
it is larger than 0. (I assume that my comment on the 2 UPDATE statements
above regarding the conditions was correct...)
--
Knut Stolze
Information Integration
IBM Germany / University of Jena This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Soefara |
last post by:
Dear Sirs,
I have been developing an application on Windows with MySQL 3.23,
making use of temporary tables.
Now when I try to port the application to a Unix box running
also MySQL 3.23, I...
|
by: Ryan |
last post by:
Just a quicky about temporarary tables. If using QA, when you create a
temporary table, it gets dropped if you close the query. Otherwise you
need to state 'DROP TABLE myTable' so that you can...
|
by: randi_clausen |
last post by:
Using SQL against a DB2 table the 'with' key word is used to
dynamically create a temporary table with an SQL statement that is
retained for the duration of that SQL statement.
What is the...
|
by: Sampath Reddy |
last post by:
Hi Everybody,
We are using UDB v8.1
I will explain about my Stored procedures which we are executing in
UDB AIX box. We have 3 millions(apporox) of data in 22 tables. By
applying the business...
|
by: Keith Watson |
last post by:
Hi, we are currently implementing an application running on DB2 V7 on
Z/OS using largely COBOL stored procedures, managed using WLM.
Some of these stored procedures declared global temporary...
|
by: Chuck Crews |
last post by:
I am interested in declaring a global temporary table within an
application. The application processes 1 set of 600 or less rows each
iteration.
Multiple programs can and do call this one...
|
by: Mike Ridley |
last post by:
I have 2 databases called (for example) "progs.mdb" and "files.mdb".
Both these databases reside on computer "myserver". The progs database
has links to the tables in the files database....
|
by: Zlatko Matić |
last post by:
I tried to work with postgres temporary tables from MS Access, but
unsuccessfully...
I was able to create temporary table by pass-through query, also I succeeded
in creating linked table through...
|
by: Stefan van Roosmalen |
last post by:
Hi there,
Is there a way to list the TEMPORATY tables?
I have tried SHOW TABLES, but this command only list the regular tables.
Thank you very much for your answer.
Regards,
Stefan.
|
by: Rahul B |
last post by:
Hi,
I have very little knowledge about creating Procedures/functions in
DB2.
When i tried to create the test function like
CREATE FUNCTION GET_TEST
(P_TEST_ID INTEGER,
P_SEL_OR_SORT...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |