473,770 Members | 4,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple Temp Tables

4 New Member
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 3179
Hevan
17 New Member
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
santoshsri
48 New Member
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
2035
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 tables. There are two requirements: the temp tables cannot be permanent members of the schema and application has to be self sufficient in create database links - users cannot be asked for that.
0
1990
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 and delete tables etc. I'd like the web user to be able to create/drop temporary tables for some processing that requires a temp table. It seems that to create a temp table you have to have the same create rights as if that use could create...
2
2039
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 purchased items. any ideas or hints would bery much appreciated rgds
5
2860
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 tried to use an override of the SESSION functions, but that isn't working in the way I would like it to. I go into mysql and can see that the temp tables that were created for the user are still in the database. Also, I would have liked to have...
1
4464
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 variables over temp tables. I also know I can't create indexes as I can on temp tables. Instead I'll have to create either a primary key and/or a unique index on a table variable. One question I have is let's say I will be putting thousands
6
3807
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. These were created with SMS and reside on the same disk and filesystem (separate directory on filesystem). One is called temp_4k and the other temp_sys. I would assume that the temp_sys was intended for use by the db2 catalog. I know of no way...
0
1482
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 how db2 handles multiple temp tablespaces of the same page size? 2) I had read somewhere that with multiple temp tablespaces of the
6
3301
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 operations in a stored procedure are treated as a transaction? Any help will be greatly appreciated. Background: We need to use temp table to pass recordsets from a nested stored procedure to a calling stored procedure. Our understanding is
4
2350
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 that gets generated for the SPROC does not have a return type. Any ideas why this is? I am referring to Scott Guthrie's blog article here: ...
0
9602
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9439
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10071
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10017
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9882
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8905
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7431
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.