473,626 Members | 3,484 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_L AST_UNIQUE_ID, and the field is LASTKEY. When I try to build the procedure I get the following message:

SDE.SP_GEN_UNIQ UE_ID - Build started.
Create stored procedure returns -20112.
SDE.SP_GEN_UNIQ UE_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_UNIQ UE_ID - Build failed.
SDE.SP_GEN_UNIQ UE_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_UNIQ UE_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_L AST_UNIQUE_ID;

SET lastKEY = lastKEY + 1;

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

COMMIT;
END P1
Jan 10 '07 #1
1 4300
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_L AST_UNIQUE_ID);
SET newUniqueKey = lastUniqueKey + 1;
UPDATE LOADER.CAD_AT_L AST_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_L AST_UNIQUE_ID, and the field is LASTKEY. When I try to build the procedure I get the following message:

SDE.SP_GEN_UNIQ UE_ID - Build started.
Create stored procedure returns -20112.
SDE.SP_GEN_UNIQ UE_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_UNIQ UE_ID - Build failed.
SDE.SP_GEN_UNIQ UE_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_UNIQ UE_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_L AST_UNIQUE_ID;

SET lastKEY = lastKEY + 1;

IF lastKEY >= 0 THEN
BEGIN
UPDATE LOADER.CAD_AT_L AST_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
22122
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 application server can talk to the database. I've determined the failure occurs when the the following statement is executed: cstmt.execute(); (due to the failure of println statements placed afterwards). I get the following error after trying to...
0
6693
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 Visual Basic .NET version of this article, see 308049. For a Microsoft Visual C++ .NET version of this article, see 310071. For a Microsoft Visual J# .NET version of this article, see 320627. This article refers to the following Microsoft .NET...
3
2799
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" when I launched the IBM Distributed Debugger via D:\IBMDebug>idebug.exe -qdaemon -quiport=8000,8001 First, a bit of background. I am running DB2 V7.2 with Fixpack 9 applied on Windows XP Professional (all critical service applied). I've written...
8
7932
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 created a temporary database with a tables space. Verified that DECLARE GLOBAL TEMPORARY TABLE TEMP (A INTEGER); INSERT INTO SESSION.TEMP VALUES(10); SELECT A FROM SESSION.TEMP; works from a query tool.
2
5449
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
0
2642
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 to call them from an ASP.Net page Every modern database system has a stored procedure language. SQL Server is no different and has a relatively sophisticated and easy to use system. This article will not attempt to go into depth in explaining...
7
3711
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 it is trult not needed but due to past experience it is key to developing good reports for cliebt/server application. Here is my example which of course dopes not work and documentation on the Internet is limited. Please if anyone can clarify...
7
3451
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 'UpdateRegistrant' expects parameter '@EMail', which was not supplied. The field value was null in the database and not changed in the FormView so is null going back into the stored procedure. I'm stumped and would greatly appreciate any suggestions.
2
4100
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
8268
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
8707
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8366
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
8510
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
7199
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...
0
4093
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4202
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2628
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1512
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.