473,387 Members | 1,520 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,387 software developers and data experts.

Error in executing single dynamic query that has multiple SQL statements

sujathaeeshan
Hello,

The single dynamic query has multiple SQL statements.

for ex:

@query="DELETE FROM TABLE L.TAB1 WHERE COL1='VAL1' ;
DELETE FROM TABLE L.PTR1 HERE COL1='VAL1' ;
DELETE FROM TABLE L.ITR1 WHERE COL1='VAL1' ;"

The stored procedure that executes this statement in SQL server looks like

ALTER PROCEDURE [dbo].[TABEXECUTE]
(
@query ntext
)
AS
BEGIN
EXEC sp_executesql @query

END

It runs successfully on SQL Server. However, it fails for DB2 when i try to execute this query using EXECUTE IMMEDIATE.

As i understand, DB2 keyword EXECUTE IMMEDIATE executes single query that has no multiple statements. Hence, it is not working for the mentioned scenario.

Please let me know if there is any alternative approach or db2 keyword to run single dynamic query that has multiple statements in DB2.
(Note: I can only pass single dynamic query as parameter to stored procedure. I would really appreciate if your logic or approach is closed to this criteria)

Thanks in advance for your help!!
Aug 29 '12 #1
3 3264
Rabbit
12,516 Expert Mod 8TB
I don't understand the purpose of this stored procedure... Why create a stored procedure whose only purpose is to call another stored procedure? Just skip that middle step and call it directly.
Aug 29 '12 #2
Thanks for the reply

Here, I am just passing a dynamic query as parameter from application to stored procedure. There is no stored procedure calling another stored procedure
Aug 30 '12 #3
Rabbit
12,516 Expert Mod 8TB
Yes there is.

You are calling the stored procedure named TABEXECUTE. And all that does is call the stored procedure sp_executesql.
Aug 30 '12 #4

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

Similar topics

2
by: Shmuel | last post by:
Is it possible to query multiple statements at once? Like: $query = "set @p := 1; select @p + 1"; $results = mysql_query($query); I'm thinking of PHP4. There is in mysqli the prepare...
4
by: DG | last post by:
Hi, Can anyone advise how to execute multiple statements in a single query batch. For example- update customers set customer_name = 'Smith' where customer_name = 'Smyth'; select * from...
5
by: sgdbprog1 | last post by:
Please can someone help me with the following question. Using mainframe db2 ie on MVS OS/390 for a select against a single table will db2 use mutiple indexes? ex: select * from table1 where...
0
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list...
2
by: Annie D via AccessMonster.com | last post by:
Hi, Is it possible to use multiple statements in SQL?? (I’ve never used it before) : I have one query that i'm working with, The statements I want to use are as below, they all work...
0
by: Mark C via AccessMonster.com | last post by:
Ok bare with me on this one.... I have 1 table "Expenses" that holds about 50 fields broken down into sub categories. I have a Subform tied to a main form so that when I pull up a client it...
5
by: alingsjtu | last post by:
Hello, every body. When execute dynamic generated multiple OPENQUERY statements (which linkes to DB2) in SQLServer, I always got SQL1040N The maximum number of applications is already connected...
2
by: chets | last post by:
Hi All, I am facing problem in executing one dynamic query in PRO *C program on linux. I want to update table mytable by data MADURAI for a column mycolumn1 where primary key is myPK.I want to...
1
by: arthy | last post by:
Hi, Is it possible to execute multiple statements on to the database using a single dbconnection object.what is the drawback in using .If not possible ,then how can the execution of multiple...
0
by: harsha318 | last post by:
Hi I need to have a single query and which can have multiple statements For eg: string str = string.Empty; str = "select * from Customers;Select * from Orders"; iDB2Connection iDB2con =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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.