472,973 Members | 2,367 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,973 software developers and data experts.

Multiple Temp Tables

4
You'll have to excuse me as I'm familiar with T-SQL (SQL Server), not so much DB2 when creating stored procedures...

I'm trying to create a procedure where I build multiple temp tables (DECLARE GLOBAL TEMPORARY TABLE), insert data into each, then use those tables to insert data into a main temp table to be returned to a Crystal report.

I can create the procedure when I declare the table and insert some records:
CREATE PROCEDURE <DB>.<Name> (

IN <ParamName> INTEGER
)
LANGUAGE SQL
RESULT SETS 1
BEGIN
-- This table hold the final set of data for the report
-- One record per store per SKU
DECLARE GLOBAL TEMPORARY TABLE Stores (
<Column List>
) ;
END


...and I can create the procedure if I throw a simple cursor to return a result set:
CREATE PROCEDURE <DB>.<Name> (

IN <ParamName> INTEGER
)
LANGUAGE SQL
RESULT SETS 1
BEGIN

DECLARE C_RETURN CURSOR WITH RETURN FOR

SELECT *
FROM <DATABASE.TABLE> ;

OPEN C_RETURN ;

END


If I create the temp table, then put the cursor statement below it to select and return the contents of that table, it's throwing errors like "Token 'C_RETURN' not valid. Valid tokens: GLOBAL." on the first line of:
DECLARE C_RETURN CURSOR WITH RETURN FOR
SELECT *
FROM SESSION.Stores ;
OPEN C_RETURN ;


Any help would be greatly appreciated.
May 24 '07 #1
2 3127
Hevan
17
Hi,

Try like this

P1: BEGIN

DECLARE GLOBAL TEMPORARY TABLE SESSION.test (num integer)
WITH REPLACE ON COMMIT PRESERVE ROWS ;

p2: begin
declare cur1 cursor with return for
select * from session.test;

insert into session.test values (1);
commit ;

open cur1;

END P2 ;
end p1
May 25 '07 #2
Hi ,

I want the data of temporary table to be displayed just after insertion the data. What should be the synatx for that ?
Jun 21 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: lev | last post by:
Hello, I am attempting to migrate an MSSQL server application to Oracle. This application pulls in data from remote databases into temp tables and then does various joins of that data with local...
0
by: Engwar | last post by:
I have a web application. We have two users in the db. One for the standard website user who has only read access to the db. The other is an admin user that has full access so I can create, alter...
2
by: matt | last post by:
Hello I am developing a web based webshop with a ms sql back end, but I cannot figure out how to do connection based temp tables, so that each user gets their own temp table to hold the...
5
by: Jay | last post by:
Hey there, I have a question. Is it possible to to construct something through a combination of php and javascript that (when a browser window is closed) would drop temp tables that are used? I've...
1
by: serge | last post by:
I am running SQL Server Best Practices on a SQL 2000 database and it is recommending me to change the temp tables inside SPs to table variables. I had read already in other places to use table...
6
by: mike_dba | last post by:
Can anyone tell me why a EEE system might be created to have two separate tablespaces with the same 4k pagesize ? They both appear to be in use as I can see the underlying files being modified. ...
0
by: sethwai | last post by:
Hi, A friend of mine inheritted a system that had 2 4k temp tablespaces each assigned to a different bufferpool. This brought up a number of questions for me. 1) Does anyone know in general...
6
by: betbubble | last post by:
I need help on two questions: 1. Is temp table the only way to pass recordsets from a nested stored procedure to a calling stored procedure? Can we avoid temp tables in this case? 2. Are...
4
by: R. K. Wijayaratne | last post by:
Hi everyone, I have a SPROC which selects records into a MSSQL #temp table and then selects the records from that. I drag this SPROC onto the right-hand pane of the DBML diagram, but the method...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.