473,503 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Building a Stored Procedure

3 New Member
I am battling to get a stored procedure to build:

I have a stored procedure working in SQL Server 2000, and now need to port it to DB2. I will be accessing the stored procedure via VB.NET. The stored procedure reads a value from a table, increments the value by 1 and writes it back into the table. The table is called LOADER.CAD_AT_LAST_UNIQUE_ID, and the field is LASTKEY. When I try to build the procedure I get the following message:

SDE.SP_GEN_UNIQUE_ID - Build started.
Create stored procedure returns -20112.
SDE.SP_GEN_UNIQUE_ID: 31: [IBM][CLI Driver][DB2/NT] SQL20112N A SAVEPOINT cannot be set because a SAVEPOINT already exists and nested SAVEPOINTS are not supported. LINE NUMBER=31. SQLSTATE=3B002
SDE.SP_GEN_UNIQUE_ID - Build failed.
SDE.SP_GEN_UNIQUE_ID - Roll back completed successfully.

My code is below. Having consulted the redbook on migrating from SQL Server to DB2, and it's content on SAVEPOINTS, I do not see that I am using these and do not understand why the compiler is reporting the above error.

CREATE PROCEDURE SDE.SP_GEN_UNIQUE_ID (OUT lastKey bigint)
------------------------------------------------------------------------
-- SQL Stored Procedure
/* This procedure retrieves the Last Assigned Key from the Table */
/* The Last Assigned Key is increased by 1 and written back */
------------------------------------------------------------------------
LANGUAGE SQL
-- Transaction has to be atomic if we
-- wish to be able to roll back changes
P1: BEGIN ATOMIC

SELECT LASTKEY INTO lastKEY
FROM LOADER.CAD_AT_LAST_UNIQUE_ID;

SET lastKEY = lastKEY + 1;

IF lastKEY >= 0 THEN
BEGIN
UPDATE LOADER.CAD_AT_LAST_UNIQUE_ID
SET LASTKEY = lastKEY;
END;
END IF;

COMMIT;
END P1
Jan 10 '07 #1
1 4281
gregoryday
3 New Member
Hi All,

Sorted out the problem. I started from scratch, and pieced it all together properly. Working code:

CREATE PROCEDURE SDE.PROCEDURE1 (OUT newUniqueKey BIGINT)
------------------------------------------------------------------------
-- SQL Stored Procedure
------------------------------------------------------------------------
P1: BEGIN
DECLARE lastUniqueKey BIGINT DEFAULT -9999;

SET lastUniqueKey = (SELECT LASTKEY FROM LOADER.CAD_AT_LAST_UNIQUE_ID);
SET newUniqueKey = lastUniqueKey + 1;
UPDATE LOADER.CAD_AT_LAST_UNIQUE_ID SET LASTKEY = newUniqueKey;

END P1



I am battling to get a stored procedure to build:

I have a stored procedure working in SQL Server 2000, and now need to port it to DB2. I will be accessing the stored procedure via VB.NET. The stored procedure reads a value from a table, increments the value by 1 and writes it back into the table. The table is called LOADER.CAD_AT_LAST_UNIQUE_ID, and the field is LASTKEY. When I try to build the procedure I get the following message:

SDE.SP_GEN_UNIQUE_ID - Build started.
Create stored procedure returns -20112.
SDE.SP_GEN_UNIQUE_ID: 31: [IBM][CLI Driver][DB2/NT] SQL20112N A SAVEPOINT cannot be set because a SAVEPOINT already exists and nested SAVEPOINTS are not supported. LINE NUMBER=31. SQLSTATE=3B002
SDE.SP_GEN_UNIQUE_ID - Build failed.
SDE.SP_GEN_UNIQUE_ID - Roll back completed successfully.

My code is below. Having consulted the redbook on migrating from SQL Server to DB2, and it's content on SAVEPOINTS, I do not see that I am using these and do not understand why the compiler is reporting the above error.

CREATE PROCEDURE SDE.SP_GEN_UNIQUE_ID (OUT lastKey bigint)
------------------------------------------------------------------------
-- SQL Stored Procedure
/* This procedure retrieves the Last Assigned Key from the Table */
/* The Last Assigned Key is increased by 1 and written back */
------------------------------------------------------------------------
LANGUAGE SQL
-- Transaction has to be atomic if we
-- wish to be able to roll back changes
P1: BEGIN ATOMIC

SELECT LASTKEY INTO lastKEY
FROM LOADER.CAD_AT_LAST_UNIQUE_ID;

SET lastKEY = lastKEY + 1;

IF lastKEY >= 0 THEN
BEGIN
UPDATE LOADER.CAD_AT_LAST_UNIQUE_ID
SET LASTKEY = lastKEY;
END;
END IF;

COMMIT;
END P1
Jan 10 '07 #2

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

Similar topics

3
22091
by: dinesh prasad | last post by:
I'm trying to use a servlet to process a form, then send that data to an SQL server stored procedure. I'm using the WebLogic 8 App. server. I am able to retrieve database information, so I know my...
0
6678
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
3
2784
by: Rhino | last post by:
I've spent the last couple of hours trying to figure out how to debug a Java stored procedure and am just going in circles. The last straw came when I got "Cannot open input stream for default"...
8
7893
by: Thomasb | last post by:
With a background in MS SQL Server programming I'm used to temporary tables. Have just started to work with DB2 ver 7 on z/OS and stumbled into the concept of GLOBAL TEMPORARY TABLE. I have...
2
5436
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
0
2630
by: Amber | last post by:
Stored procedures are faster and more efficient than in-line SQL statements. In this article we will look at two SQL Server stored procedures; one using an input parameter and one not, and see how...
7
3702
by: rzagars | last post by:
I have just started working on DB2 which the syntax is a lot different. I am trying to create a SQL stored procedure for generating reports. I want to use temporary database which in this example...
7
3430
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function...
2
4079
by: jed | last post by:
I have created this example in sqlexpress ALTER PROCEDURE . @annualtax FLOAT AS BEGIN SELECT begin1,end1,deductedamount,pecentageextra FROM tax
0
7198
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,...
0
7072
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...
0
7271
Oralloy
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,...
0
7319
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...
1
4998
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...
0
4666
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...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.