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

Procedure variable scope?

I am using DB2 on AS400. I am trying to use a variable in a CREATE
TABLE AS statement. However, I am informed that the variable is not a
column of the FROM table... It feels like a scope issue in the SELECT,
but I don't see how. Please help, I hate getting frustrated by
something so basic.

In the procedure below, the first statement compiles fine. The second
does not, with the error "Position n Column MYVAR not in table
MYTABLE".

CREATE PROCEDURE MYPROC(IN MYVAR CHAR(8))
LANGUAGE SQL

BEGIN

INSERT INTO TEST1
SELECT
FIELDA
FROM MYTABLE
WHERE FIELDA = MYVAR;

CREATE TABLE TEST2 AS (
SELECT
FIELDA
FROM MYTABLE
WHERE FIELDA = MYVAR
) WITH DATA;

END
Feb 25 '08 #1
1 1669
ShaggyMoose wrote:
I am using DB2 on AS400. I am trying to use a variable in a CREATE
TABLE AS statement. However, I am informed that the variable is not a
column of the FROM table... It feels like a scope issue in the SELECT,
but I don't see how. Please help, I hate getting frustrated by
something so basic.

In the procedure below, the first statement compiles fine. The second
does not, with the error "Position n Column MYVAR not in table
MYTABLE".

CREATE PROCEDURE MYPROC(IN MYVAR CHAR(8))
LANGUAGE SQL

BEGIN

INSERT INTO TEST1
SELECT
FIELDA
FROM MYTABLE
WHERE FIELDA = MYVAR;

CREATE TABLE TEST2 AS (
SELECT
FIELDA
FROM MYTABLE
WHERE FIELDA = MYVAR
) WITH DATA;

END
DB2 does not allow the usage of variables in DDL statements.

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Feb 25 '08 #2

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

Similar topics

3
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...
4
by: Toonman | last post by:
I'm trying to use a couple of variables in a stored procedure. Things work fine when I hard code the data into the variables and also work fine when I use the variable in the WHERE clause and hard...
3
by: Grant Wagner | last post by:
Given the following working code: function attributes() { var attr1 = arguments || '_'; var attr2 = arguments || '_'; return ( function (el1, el2) { var value1 = el1 + el1; var value2 = el2...
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
10
by: MLH | last post by:
I was wondering if setting object vars to Nothing near the end of a sub procedure was beneficial at all - since they (the OV's) are about to go out-a-scope anyway? For example, Sub MySub()...
9
by: fniles | last post by:
I am using VB.NET 2003 and SQL2000 database. I have a stored procedure called "INSERT_INTO_MYTABLE" that accepts 1 parameter (varchar(10)) and returns the identity column value from that table....
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
4
by: rinal86 | last post by:
hi i'm rizki. can you all help me? please i have a problem with script php to call procedure using sql server database this is the store procedure in sql server: CREATE Procedure dbo.q_putaka...
112
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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...
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...

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.