473,386 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Need Help Converting MS SQL Server Stored Procedures to DB2

Hi!
I'm a newbie at DB2 but have 13 years of SQL Server. I need to convert over
100 SQL Server procs to DB2. I haven't had much luck with the IBM
Integration Toolkit and want to avoid ER/win templates. Any suggestions.
Thanks.
Adam
Nov 12 '05 #1
8 7297
Not sure what toolkit you are referring to have you tried the migration
toolkit?
http://www-306.ibm.com/software/data/db2/migration/mtk/
The toolkit does a fairly good job with a usual conversion rate around
80%-90%. I doubt you will find a toll doing better than that.
Given that any tool will deliver an "emulation" of the source DBMS you
then need to hand tune those procedures that are performance critical.
Don't be affraid of order-of-magnitude improvement requirements.
A migration tool produces so much fluff to achieve correctness that it's
easy to improve upon.

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab

Nov 12 '05 #2
Serge,
Thanks for your reponse. I am using that toolkit and actually, it is quite
good. It doesn't seem to handle user-defined datatypes even though they
exist in db2 but I can manually tweak the code. I'm more concerned, however,
about the fact that the converted db2 stored procedures use cursors while
the MS SQL procs do not. I've always tried to avoid cursors in SQL Server as
they run much slower than result-set oriented code. Is the same thing not
true in db2? Your help is appreciated.

Cheers,
Adam
"Serge Rielau" <sr*****@ca.eye-bee-m.com> wrote in message
news:bu**********@hanover.torolab.ibm.com...
Not sure what toolkit you are referring to have you tried the migration
toolkit?
http://www-306.ibm.com/software/data/db2/migration/mtk/
The toolkit does a fairly good job with a usual conversion rate around
80%-90%. I doubt you will find a toll doing better than that.
Given that any tool will deliver an "emulation" of the source DBMS you
then need to hand tune those procedures that are performance critical.
Don't be affraid of order-of-magnitude improvement requirements.
A migration tool produces so much fluff to achieve correctness that it's
easy to improve upon.

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab

Nov 12 '05 #3
Adam,

The same is true in DB2. However MTK's first concern is with correctness.
There may be some behavior or feature in SQL Server that is different
enough from DB2 so the MTK felt the need to transpose to cursors.
Possibly there are function calls that were mapped to procedures?
If you show me an example (T-SQL vs generated SQL PL) I may be able to
tell you why the MTK worked the way it did.
Also not ethat you can send comments and requests to mt*@us.ibm.com
The MTK team is very eager to improve the tool and they have a quick
turnaround.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab

Nov 12 '05 #4
Serge,

Thanks for your quick reply. Attached are examples of the T-SQL code vs. the
SQL PL code.

TSQL:

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE PROCEDURE GetApplDirectiveByAgency_SP
(
@AgencyID udt_Agency = NULL,
@ApplicationID1 udt_Application = NULL
)
AS
BEGIN
DECLARE
@ReturnValue udt_ReturnValue,
@Exist udt_Exist,
@Row udt_Row,
@Sequence udt_Sequence,
@errorNumber udt_ErrorNumber,
@errorText udt_ErrorText,
@AgencyID1 udt_Application
SELECT @AgencyID1 = Agency_Network.AgencyID1
FROM Agency_Network INNER JOIN Agency_Network Agency_Network_1
ON Agency_Network.AgencyID1 = Agency_Network_1.AgencyID2
WHERE (Agency_Network.RelationshipID = 'Includes')
AND (Agency_Network_1.AgencyID1 = 'User Roles')
AND (Agency_Network_1.RelationshipID = 'Includes')
AND (Agency_Network.AgencyID2 = @AgencyID)
SELECT DISTINCT @AgencyID1 'AgencyID',
Application_Directive.ApplicationID,
Application_Directive.DirectiveType,
Application_Directive.Directive,
Application_Directive.Note,
Application_Directive.HistoryRevisionCount
FROM [Application_Network],
[Application_Directive],
[Agency_Application]
WHERE Application_Network.ApplicationID2 =
Application_Directive.ApplicationID
AND Agency_Application.ApplicationID =
Application_Directive.ApplicationID
AND (Agency_Application.AgencyID = @AgencyID
OR Agency_Application.AgencyID IN (
SELECT Agency_Network.AgencyID1
FROM Agency_Network INNER JOIN Agency_Network Agency_Network_1
ON Agency_Network.AgencyID1 = Agency_Network_1.AgencyID2
WHERE (Agency_Network.RelationshipID = 'Includes')
AND (Agency_Network_1.AgencyID1 = 'User Roles')
AND (Agency_Network_1.RelationshipID = 'Includes')
AND (Agency_Network.AgencyID2 = @AgencyID)))
AND Application_Network.ApplicationID1 = @ApplicationID1
ORDER BY
AgencyID,
Application_Directive.ApplicationID,
Application_Directive.DirectiveType,
Application_Directive.Directive
END

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

SQL PL:

CREATE PROCEDURE db2admin.GetApplDirectiveByAgency1_SP(
IN v_AgencyID VARCHAR(75),
IN v_ApplicationID1 VARCHAR(75))
DYNAMIC RESULT SETS 1
LANGUAGE SQL
BEGIN
DECLARE SQLCODE INT;
DECLARE v_ReturnValue INT;
DECLARE v_Exist INT;
DECLARE v_Row INT;
DECLARE v_Sequence INT;
DECLARE v_errorNumber INT;
DECLARE v_errorText VARCHAR(64);
DECLARE v_AgencyID1 VARCHAR(75);
DECLARE l_sqlcode INT DEFAULT 0;
DECLARE temp_cursor CURSOR WITH HOLD WITH RETURN TO CLIENT FOR
SELECT DISTINCT v_AgencyID1 AS AgencyID,
db2admin.Application_Directive.ApplicationID,
db2admin.Application_Directive.DirectiveType,
db2admin.Application_Directive.Directive,
db2admin.Application_Directive.Note,
db2admin.Application_Directive.HistoryRevisionCoun t
FROM db2admin.Application_Network, db2admin.Application_Directive,
db2admin.Agency_Application
WHERE db2admin.Application_Network.ApplicationID2 =
db2admin.Application_Directive.ApplicationID AND
db2admin.Agency_Application.ApplicationID =
db2admin.Application_Directive.ApplicationID AND
(CAST(db2admin.Agency_Application.AgencyID AS VARCHAR(75)) =
v_AgencyID
OR
db2admin.Agency_Application.AgencyID IN
(SELECT db2admin.Agency_Network.AgencyID1
FROM db2admin.Agency_Network INNER JOIN db2admin.Agency_Network AS
Agency_Network_11 ON
db2admin.Agency_Network.AgencyID1 = Agency_Network_11.AgencyID2
WHERE CAST(db2admin.Agency_Network.RelationshipID AS VARCHAR(75)) =
'Includes' AND
CAST(Agency_Network_11.AgencyID1 AS VARCHAR(75)) =
'User Roles' AND
CAST(Agency_Network_11.RelationshipID AS VARCHAR(75)) =
'Includes' AND
CAST(db2admin.Agency_Network.AgencyID2 AS VARCHAR(75)) =
v_AgencyID))
AND
CAST(db2admin.Application_Network.ApplicationID1 AS VARCHAR(75)) =
v_ApplicationID1
ORDER BY AgencyID, db2admin.Application_Directive.ApplicationID,
db2admin.Application_Directive.DirectiveType,
db2admin.Application_Directive.Directive ;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION,SQLWARNING,NOT FOUND
SET l_sqlcode = SQLCODE;

SELECT db2admin.Agency_Network.AgencyID1
INTO v_AgencyID1
FROM db2admin.Agency_Network INNER JOIN db2admin.Agency_Network AS
Agency_Network_1 ON
db2admin.Agency_Network.AgencyID1 = Agency_Network_1.AgencyID2
WHERE CAST(db2admin.Agency_Network.RelationshipID AS VARCHAR(75)) =
'Includes' AND
CAST(Agency_Network_1.AgencyID1 AS VARCHAR(75)) = 'User Roles' AND
CAST(Agency_Network_1.RelationshipID AS VARCHAR(75)) = 'Includes'
AND
CAST(db2admin.Agency_Network.AgencyID2 AS VARCHAR(75)) = v_AgencyID
FETCH FIRST 1 ROWS ONLY;
OPEN temp_cursor;
END

Any insights you may have would be greatly appreciated. I'll jot down mtk's
email address. Thanks.

Adam

"Serge Rielau" <sr*****@ca.eye-bee-m.com> wrote in message
news:bu**********@hanover.torolab.ibm.com...
Adam,

The same is true in DB2. However MTK's first concern is with correctness.
There may be some behavior or feature in SQL Server that is different
enough from DB2 so the MTK felt the need to transpose to cursors.
Possibly there are function calls that were mapped to procedures?
If you show me an example (T-SQL vs generated SQL PL) I may be able to
tell you why the MTK worked the way it did.
Also not ethat you can send comments and requests to mt*@us.ibm.com
The MTK team is very eager to improve the tool and they have a quick
turnaround.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab

Nov 12 '05 #5
AK
Adam,
good. It doesn't seem to handle user-defined datatypes even though they
exist in db2 but I can manually tweak the code.
please be careful: user-defined datatypes in DB2 are very different
from user-defined datatypes in MS SQL Server.
I'm more concerned, however,
about the fact that the converted db2 stored procedures use cursors while
the MS SQL procs do not.


In SQL Server you can just write
SELECT * FROM SOME_TABLE
in an SP, the client will get a result set

To accomplish the same in DB2 you have to open a cursor, that's
normal.
Are you speaking about that?

There is a great book:
DB2 SQL Procedural Language for Linux, Unix and Windows
Paul Yip, Drew Bradstock, Hana Curtis, Michael X. Gao, Zamil
Janmohamed
Nov 12 '05 #6
Thanks for your reply. The udts will be going so they won't be a problem.
The cursor I referred was the same as the one that you say is "normal" in
DB2. That's a relief. I have the very book you mentioned in front of me!

Have you had any success using ER/win templates to convert stored procs?

Adam
"AK" <ak************@yahoo.com> wrote in message
news:46**************************@posting.google.c om...
Adam,
good. It doesn't seem to handle user-defined datatypes even though they
exist in db2 but I can manually tweak the code.


please be careful: user-defined datatypes in DB2 are very different
from user-defined datatypes in MS SQL Server.
I'm more concerned, however,
about the fact that the converted db2 stored procedures use cursors while the MS SQL procs do not.


In SQL Server you can just write
SELECT * FROM SOME_TABLE
in an SP, the client will get a result set

To accomplish the same in DB2 you have to open a cursor, that's
normal.
Are you speaking about that?

There is a great book:
DB2 SQL Procedural Language for Linux, Unix and Windows
Paul Yip, Drew Bradstock, Hana Curtis, Michael X. Gao, Zamil
Janmohamed

Nov 12 '05 #7
That code is fine. It's how the SQL Standard handles passing of result
sets. Implicitly MS SQL Server/Sybase will also have to pass a resultset.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab

Nov 12 '05 #8
AK
>
Have you had any success using ER/win templates to convert stored procs?


No, there was a decision to re-write them manually.
The reason: error handling in SQL/PL is entirely different.
Nov 12 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: polytimi8 | last post by:
Hello, I would like to know if it is possible to create a form in Access2000, which would function like a calendar for 8 operating rooms in hospital, showing which hours are those closed for a...
5
by: Ralph | last post by:
Hi all, I'm a newbie to MS-SQL UDFs and seem to have a real big problem. I need to implement a logic to receive an adress build out of various user definable fields from various user defined...
18
by: Robin Lawrie | last post by:
Hi again, another problem! I've moved from an Access database to SQL server and am now having trouble inserting dates and times into seperate fields. I'm using ASP and the code below to get the...
5
by: gilles27 | last post by:
I've ready many of the posts on this and other newsgroups in which people describe working practices for source control of database scripts. We are looking to implement something similar in my...
11
by: jrefactors | last post by:
I want to know the differences between SQL Server 2000 stored procedures and oracle stored procedures? Do they have different syntax? The concept should be the same that the stored procedures...
1
by: rdshultz | last post by:
Good morning everyone. Could someone tell me if there is a book out there which gives examples of both VB.net code and creating SQL Server 2000 stored procedures and how you get them to work...
1
by: sollento | last post by:
Hi, How can I export SQL Server Stored Procedures to MS-Access? Cheers H
1
by: luna | last post by:
got so far then it broke and i cant get it working again - it was updating fine but not inserting and now im getting a "Error converting data type varchar to numeric" which i didnt have before.......
1
by: jobs | last post by:
I have a growning list of stored procedures that accept a single string as a parameter. The list and parameters are maintained in a table with two columns. Some of the Stored procedures take...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...

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.