DB2 Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDB2 Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old March 20th, 2006, 04:27 AM
bzagars bzagars is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 1 bzagars User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 36 sec
Reputation Power: 0
DB2 Stored Procedures Hekp Needed

Database Developers,

I have just started working on DB2 which the syntax is a lot different from traditional SQL engines. I am trying to create a SQL stored procedure for generating reports. I want to use temporary database which in this example it is truly not needed but due to past experience it is key to developing good reports for client/server application.

Here is my example which of course does not work and documentation on the Internet is limited about DB2. Please if anyone can clarify these scripts please let me know.

CREATE PROCEDURE LDBS_SP_SEL_MYTABLE
( IN BeginDate DATE, IN EndDate DATE )
RESULT SETS 1
LANGUAGE SQL
------------------------------------------------------------------------
-- SQL Stored Procedure
------------------------------------------------------------------------
BEGIN
DECLARE GLOBAL TEMPORARY TABLE myResults AS
(SELECT
MYTABLE.LAST_NAME,
MYTABLE.FIRST_NAME,
MYTABLE.BIRTH_DATE
FROM ADMINISTRATOR.MYTABLE AS MYTABLE
WHERE MYTABLE.BIRTH_DATE >= BeginDate
AND MYTABLE.BIRTH_DATE < EndDate)
DEFINITION ONLY NOT LOGGED;
BEGIN
--Declare client cursor
DECLARE cursor1 CURSOR WITH RETURN TO CLIENT FOR
SELECT
LAST_NAME,
FIRST_NAME,
BIRTH_DATE
FROM SESSION.myResults;
--Cursor left open for client application
OPEN cursor1;
END;
END


Also I tried to use the INSERT INTO which is common usage on other SQL engines.

BEGIN
DECLARE GLOBAL TEMPORARY TABLE myResults
LIKE ADMINISTRATOR.MYTABLE
ON COMMIT DELETE ROWS
NOT LOGGED
IN USERTEMPSPACE1;
INSERT INTO SESSION.myResults
SELECT
MYTABLE.LAST_NAME,
MYTABLE.FIRST_NAME,
MYTABLE.BIRTH_DATE
FROM ADMINISTRATOR.MYTABLE AS MYTABLE
WHERE MYTABLE.BIRTH_DATE >= BeginDate
AND MYTABLE.BIRTH_DATE < EndDate;
END


Also on the second code example I tried to show the result and I am not sure what is right. Personally and with other SQL engines I do not have to use cursors which I can just select my result set.

-- Declare cursor
DECLARE cursor1 CURSOR WITH RETURN FOR
SELECT
MYRESULTS.LAST_NAME,
MYRESULTS.FIRST_NAME,
MYRESULTS.BIRTH_DATE
FROM SESSION.myResults AS MYRESULTS;
-- Cursor left open for client application
OPEN cursor1;


Or just

SELECT * FROM SESSION.myResults;

Both of these code blocks come up with errors. I have to develop a standard for returning data which is readable in SQL format. What I want to accomplish is populating a temporary table and then sending the results to the client. I would appreciate anyone’s input and wisdom.

Best Regards,

Bob Zagars

Reply With Quote
  #2  
Old March 21st, 2006, 09:21 AM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
The documentation is out there, but it is hard to find

Try this:
http://www-306.ibm.com/software/dat.../v8/stpUDF.html
__________________
~Nemi

Before posting did you try:
[ Javadocs | Google ]

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDB2 Development > DB2 Stored Procedures Hekp Needed


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway