473,413 Members | 2,066 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,413 software developers and data experts.

Help needed : How to Execute a string SQL statement with DB2

Hi,

I'm now working with DB2, and I can't find out how to execute the
contents of a string Statement, without using a Java/... procedure,
only using SQL statements.
I know that some SQBDs such as SQL Server allows it as the exemple
bellow shows :
EXECUTE 'SELECT * FROM Test'

Is there any way to do so with DB2 ?

Thanks by advance,

Cédric
Nov 12 '05 #1
6 5357

"Doohan W." <do****@caramail.com> wrote in message
news:43**************************@posting.google.c om...
Hi,

I'm now working with DB2, and I can't find out how to execute the
contents of a string Statement, without using a Java/... procedure,
only using SQL statements.
I know that some SQBDs such as SQL Server allows it as the exemple
bellow shows :
EXECUTE 'SELECT * FROM Test'

Is there any way to do so with DB2 ?

Thanks by advance,

Your question isn't very clear so it is very hard to answer. Do you want to
execute this "string Statement" from a command line or in an application? If
you are executing in an application, what language is the application using?

Also, what DB2 version are you using? What operating system are you using?

Rhino
Nov 12 '05 #2
"Rhino" <rh****@NOSPAM.sympatico.ca> wrote in message news:<4s********************@news20.bellglobal.com >...
"Doohan W." <do****@caramail.com> wrote in message
news:43**************************@posting.google.c om...
Hi,

I'm now working with DB2, and I can't find out how to execute the
contents of a string Statement, without using a Java/... procedure,
only using SQL statements.
I know that some SQBDs such as SQL Server allows it as the exemple
bellow shows :
EXECUTE 'SELECT * FROM Test'

Is there any way to do so with DB2 ?

Thanks by advance,

Your question isn't very clear so it is very hard to answer. Do you want to
execute this "string Statement" from a command line or in an application? If
you are executing in an application, what language is the application using?

Also, what DB2 version are you using? What operating system are you using?

Rhino


Hi,

Well, my matter is the following :
I need to retrieve the description of all the products that are of
the same type.
According to the model chosen, the description is not in the Product
table, but in a Detail table, which is different for each type of
product and has its name contained in the ProductType table (some kind
of dynamic access).
For example, here is the description of the tables used :
CREATE TABLE ProductType(
CType CHAR(3),
...,
TableName VARCHAR(50),
LabelName VARCHAR(50),
KeyProduct VARCHAR(50),
...
)
CREATE TABLE Product(
NPRD DECIMAL(10),
CType CHAR(3),
...,
CommercialReference DECIMAL(10),
...
)
CREATE TABLE DetailVPC(
NVPC DECIMAL(10),
...,
LDES VARCHAR(255),
...,
CREFPRD DECIMAL(10)
)
CREATE TABLE DetailABO(
NABO DECIMAL(8),
...,
LABODES VARCHAR(255),
...,
NREFPRD DECIMAL(10)
)

Having some network overflow, I need to reduce the number of
requests.
Thus, here is the SQL request I had with SQL Server (This piece of
code was in an SQL procedure) :

DECLARE @SQL AS VARCHAR(1000)
SELECT @SQL = 'SELECT P.NPRD AS ProductNumber, P.CommercialReference,
X.' + LabelName + ' AS Description FROM Product AS P INNER JOIN ' +
TableName + ' AS X ON X.' + ProductKey + ' = P.NPRD' FROM ProductType
WHERE CType = @ProductType
EXECUTE @SQL

I'd like to know if DB2 allows me to do so using only SQL statements
(DB2 v8.1.4 using both AS400 and ZLinux).
I've got some alternative ways of working, such as writing the
procedure in JAVA, but my boss'd rather not as JAVA is not understood
by every one in the firm.

Thanks.

Cédric
Nov 12 '05 #3

"Doohan W." <do****@caramail.com> wrote in message
news:43**************************@posting.google.c om...
"Rhino" <rh****@NOSPAM.sympatico.ca> wrote in message

news:<4s********************@news20.bellglobal.com >...
"Doohan W." <do****@caramail.com> wrote in message
news:43**************************@posting.google.c om...
Hi,

I'm now working with DB2, and I can't find out how to execute the
contents of a string Statement, without using a Java/... procedure,
only using SQL statements.
I know that some SQBDs such as SQL Server allows it as the exemple
bellow shows :
EXECUTE 'SELECT * FROM Test'

Is there any way to do so with DB2 ?

Thanks by advance,

Your question isn't very clear so it is very hard to answer. Do you want to execute this "string Statement" from a command line or in an application? If you are executing in an application, what language is the application using?
Also, what DB2 version are you using? What operating system are you using?
Rhino


Hi,

Well, my matter is the following :
I need to retrieve the description of all the products that are of
the same type.
According to the model chosen, the description is not in the Product
table, but in a Detail table, which is different for each type of
product and has its name contained in the ProductType table (some kind
of dynamic access).
For example, here is the description of the tables used :
CREATE TABLE ProductType(
CType CHAR(3),
...,
TableName VARCHAR(50),
LabelName VARCHAR(50),
KeyProduct VARCHAR(50),
...
)
CREATE TABLE Product(
NPRD DECIMAL(10),
CType CHAR(3),
...,
CommercialReference DECIMAL(10),
...
)
CREATE TABLE DetailVPC(
NVPC DECIMAL(10),
...,
LDES VARCHAR(255),
...,
CREFPRD DECIMAL(10)
)
CREATE TABLE DetailABO(
NABO DECIMAL(8),
...,
LABODES VARCHAR(255),
...,
NREFPRD DECIMAL(10)
)

Having some network overflow, I need to reduce the number of
requests.
Thus, here is the SQL request I had with SQL Server (This piece of
code was in an SQL procedure) :

DECLARE @SQL AS VARCHAR(1000)
SELECT @SQL = 'SELECT P.NPRD AS ProductNumber, P.CommercialReference,
X.' + LabelName + ' AS Description FROM Product AS P INNER JOIN ' +
TableName + ' AS X ON X.' + ProductKey + ' = P.NPRD' FROM ProductType
WHERE CType = @ProductType
EXECUTE @SQL

I'd like to know if DB2 allows me to do so using only SQL statements
(DB2 v8.1.4 using both AS400 and ZLinux).
I've got some alternative ways of working, such as writing the
procedure in JAVA, but my boss'd rather not as JAVA is not understood
by every one in the firm.

I think I'm going to let someone else try to answer your question; I have
very little familiarity with DB2 on AS/400 and none with ZLinux.
Furthermore, I'm confused when you say you are using DB2 V8.1.4 on AS/400:
as far as I can determine from the IBM site, the latest version of DB2 on
AS/400 is V5.3.

Rhino
Nov 12 '05 #4
This statement...

EXECUTE IMMEDIATE variable

will dynamically execute the statement in the string variable. It
doesn't work for SELECT statements; DB2 SQL syntax is a bit behind the
times :)

Breck

do****@caramail.com (Doohan W.) wrote in message news:<43**************************@posting.google. com>...
"Rhino" <rh****@NOSPAM.sympatico.ca> wrote in message news:<4s********************@news20.bellglobal.com >...
"Doohan W." <do****@caramail.com> wrote in message
news:43**************************@posting.google.c om...
Hi,

I'm now working with DB2, and I can't find out how to execute the
contents of a string Statement, without using a Java/... procedure,
only using SQL statements.
I know that some SQBDs such as SQL Server allows it as the exemple
bellow shows :
EXECUTE 'SELECT * FROM Test'

Is there any way to do so with DB2 ?

Thanks by advance,

Your question isn't very clear so it is very hard to answer. Do you want to
execute this "string Statement" from a command line or in an application? If
you are executing in an application, what language is the application using?

Also, what DB2 version are you using? What operating system are you using?

Rhino


Hi,

Well, my matter is the following :
I need to retrieve the description of all the products that are of
the same type.
According to the model chosen, the description is not in the Product
table, but in a Detail table, which is different for each type of
product and has its name contained in the ProductType table (some kind
of dynamic access).
For example, here is the description of the tables used :
CREATE TABLE ProductType(
CType CHAR(3),
...,
TableName VARCHAR(50),
LabelName VARCHAR(50),
KeyProduct VARCHAR(50),
...
)
CREATE TABLE Product(
NPRD DECIMAL(10),
CType CHAR(3),
...,
CommercialReference DECIMAL(10),
...
)
CREATE TABLE DetailVPC(
NVPC DECIMAL(10),
...,
LDES VARCHAR(255),
...,
CREFPRD DECIMAL(10)
)
CREATE TABLE DetailABO(
NABO DECIMAL(8),
...,
LABODES VARCHAR(255),
...,
NREFPRD DECIMAL(10)
)

Having some network overflow, I need to reduce the number of
requests.
Thus, here is the SQL request I had with SQL Server (This piece of
code was in an SQL procedure) :

DECLARE @SQL AS VARCHAR(1000)
SELECT @SQL = 'SELECT P.NPRD AS ProductNumber, P.CommercialReference,
X.' + LabelName + ' AS Description FROM Product AS P INNER JOIN ' +
TableName + ' AS X ON X.' + ProductKey + ' = P.NPRD' FROM ProductType
WHERE CType = @ProductType
EXECUTE @SQL

I'd like to know if DB2 allows me to do so using only SQL statements
(DB2 v8.1.4 using both AS400 and ZLinux).
I've got some alternative ways of working, such as writing the
procedure in JAVA, but my boss'd rather not as JAVA is not understood
by every one in the firm.

Thanks.

Cédric

Nov 12 '05 #5
Thanks Breck...
I'll make up with this.

Cédric

bc*****@risingroad.com (Breck Carter) wrote in message news:<f2**************************@posting.google. com>...
This statement...

EXECUTE IMMEDIATE variable

will dynamically execute the statement in the string variable. It
doesn't work for SELECT statements; DB2 SQL syntax is a bit behind the
times :)

Breck

do****@caramail.com (Doohan W.) wrote in message news:<43**************************@posting.google. com>...
"Rhino" <rh****@NOSPAM.sympatico.ca> wrote in message news:<4s********************@news20.bellglobal.com >...
"Doohan W." <do****@caramail.com> wrote in message
news:43**************************@posting.google.c om...
> Hi,
>
> I'm now working with DB2, and I can't find out how to execute the
> contents of a string Statement, without using a Java/... procedure,
> only using SQL statements.
> I know that some SQBDs such as SQL Server allows it as the exemple
> bellow shows :
> EXECUTE 'SELECT * FROM Test'
>
> Is there any way to do so with DB2 ?
>
> Thanks by advance,
>
Your question isn't very clear so it is very hard to answer. Do you want to
execute this "string Statement" from a command line or in an application? If
you are executing in an application, what language is the application using?

Also, what DB2 version are you using? What operating system are you using?

Rhino


Hi,

Well, my matter is the following :
I need to retrieve the description of all the products that are of
the same type.
According to the model chosen, the description is not in the Product
table, but in a Detail table, which is different for each type of
product and has its name contained in the ProductType table (some kind
of dynamic access).
For example, here is the description of the tables used :
CREATE TABLE ProductType(
CType CHAR(3),
...,
TableName VARCHAR(50),
LabelName VARCHAR(50),
KeyProduct VARCHAR(50),
...
)
CREATE TABLE Product(
NPRD DECIMAL(10),
CType CHAR(3),
...,
CommercialReference DECIMAL(10),
...
)
CREATE TABLE DetailVPC(
NVPC DECIMAL(10),
...,
LDES VARCHAR(255),
...,
CREFPRD DECIMAL(10)
)
CREATE TABLE DetailABO(
NABO DECIMAL(8),
...,
LABODES VARCHAR(255),
...,
NREFPRD DECIMAL(10)
)

Having some network overflow, I need to reduce the number of
requests.
Thus, here is the SQL request I had with SQL Server (This piece of
code was in an SQL procedure) :

DECLARE @SQL AS VARCHAR(1000)
SELECT @SQL = 'SELECT P.NPRD AS ProductNumber, P.CommercialReference,
X.' + LabelName + ' AS Description FROM Product AS P INNER JOIN ' +
TableName + ' AS X ON X.' + ProductKey + ' = P.NPRD' FROM ProductType
WHERE CType = @ProductType
EXECUTE @SQL

I'd like to know if DB2 allows me to do so using only SQL statements
(DB2 v8.1.4 using both AS400 and ZLinux).
I've got some alternative ways of working, such as writing the
procedure in JAVA, but my boss'd rather not as JAVA is not understood
by every one in the firm.

Thanks.

Cédric

Nov 12 '05 #6
Thanks anyway Rhino...

I'll try and get the real version number then, as it seems that my
administrator mistook... Probably a client version number instead of
the server version number I guess...

Anyway, I think this is an SQL statement usage that I miss... Perhaps
DB2 is still far from using SQL 2.

Cédric

"Rhino" <rh****@NOSPAM.sympatico.ca> wrote in message news:<YO*****************@news20.bellglobal.com>.. .
"Doohan W." <do****@caramail.com> wrote in message
news:43**************************@posting.google.c om...
"Rhino" <rh****@NOSPAM.sympatico.ca> wrote in message

news:<4s********************@news20.bellglobal.com >...
"Doohan W." <do****@caramail.com> wrote in message
news:43**************************@posting.google.c om...
> Hi,
>
> I'm now working with DB2, and I can't find out how to execute the
> contents of a string Statement, without using a Java/... procedure,
> only using SQL statements.
> I know that some SQBDs such as SQL Server allows it as the exemple
> bellow shows :
> EXECUTE 'SELECT * FROM Test'
>
> Is there any way to do so with DB2 ?
>
> Thanks by advance,
>
Your question isn't very clear so it is very hard to answer. Do you want to execute this "string Statement" from a command line or in an application? If you are executing in an application, what language is the application using?
Also, what DB2 version are you using? What operating system are you using?
Rhino


Hi,

Well, my matter is the following :
I need to retrieve the description of all the products that are of
the same type.
According to the model chosen, the description is not in the Product
table, but in a Detail table, which is different for each type of
product and has its name contained in the ProductType table (some kind
of dynamic access).
For example, here is the description of the tables used :
CREATE TABLE ProductType(
CType CHAR(3),
...,
TableName VARCHAR(50),
LabelName VARCHAR(50),
KeyProduct VARCHAR(50),
...
)
CREATE TABLE Product(
NPRD DECIMAL(10),
CType CHAR(3),
...,
CommercialReference DECIMAL(10),
...
)
CREATE TABLE DetailVPC(
NVPC DECIMAL(10),
...,
LDES VARCHAR(255),
...,
CREFPRD DECIMAL(10)
)
CREATE TABLE DetailABO(
NABO DECIMAL(8),
...,
LABODES VARCHAR(255),
...,
NREFPRD DECIMAL(10)
)

Having some network overflow, I need to reduce the number of
requests.
Thus, here is the SQL request I had with SQL Server (This piece of
code was in an SQL procedure) :

DECLARE @SQL AS VARCHAR(1000)
SELECT @SQL = 'SELECT P.NPRD AS ProductNumber, P.CommercialReference,
X.' + LabelName + ' AS Description FROM Product AS P INNER JOIN ' +
TableName + ' AS X ON X.' + ProductKey + ' = P.NPRD' FROM ProductType
WHERE CType = @ProductType
EXECUTE @SQL

I'd like to know if DB2 allows me to do so using only SQL statements
(DB2 v8.1.4 using both AS400 and ZLinux).
I've got some alternative ways of working, such as writing the
procedure in JAVA, but my boss'd rather not as JAVA is not understood
by every one in the firm.

I think I'm going to let someone else try to answer your question; I have
very little familiarity with DB2 on AS/400 and none with ZLinux.
Furthermore, I'm confused when you say you are using DB2 V8.1.4 on AS/400:
as far as I can determine from the IBM site, the latest version of DB2 on
AS/400 is V5.3.

Rhino

Nov 12 '05 #7

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

Similar topics

46
by: Kingdom | last post by:
In my data base I have a list of componet types e.g. type A - I have 8 off - type B I have 12 off etc. I'm using Set objRS = objDC.Execute("Select DISTINCT Component_Type FROM Parts_Table") ...
1
by: PT | last post by:
I got a problem. And thats..... First of all, I got these three tables. ------------------- ------------------ ---------------------- tblPerson tblPersonSoftware ...
4
by: TJS | last post by:
trying to get a record count from a stored procedure using a supplied SQL statement Error msg: =========== "The SqlParameterCollection only accepts non-null SqlParameter type objects,not...
0
by: Edwinah63 | last post by:
Hi guys, i am not new to vb6, but a mere tyro in vb.net what i want to do is the following open transaction build an ADODB command object using parameters execute it build another command...
0
by: prad | last post by:
Hi, Following java code returns 24 result sets.It counts number of rows in the first result set correctly.But doesnt count rows from next result set. When I debugged the code I found out that...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
2
by: lm247 | last post by:
Hi, I have the following script which processes the html form and inserts into 3 tables. How can I pass the value of the variable EDSID to the next page using response.redirect? Been trying to...
2
by: rookiejavadude | last post by:
I'm have most of my java script done but can not figure out how to add a few buttons. I need to add a delete and add buttong to my existing java program. Not sure were to add it on how. Can anyone...
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: 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
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
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...
0
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...
0
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,...

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.