473,602 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Could I use a host variable for replacing the table name in SQC program?

Hello all,

I would like to use same SQL statement in my SQC program for several
tables
I tried something like that:

- sql_sts="SELECT col1, col2 FROM ?"
- EXEC SQL PREPARE dsql FROM :sql_sts;
- EXEC SQL DECLARE cTab CURSOR WITH HOLD FOR dsql;
- EXEC SQL OPEN cTab USING :tabName;
EXEC SQL FETCH cTab;
- EXEC SQL CLOSE cTab;

where tabName is a parameter, and it does not work!
Could I use a host variable like this way in my SQC?
Thanks for your help

Y.

Jul 6 '06 #1
3 1863
Which db2 version and fixpak on which operating system?
What is the exact error that you get ?

Jul 7 '06 #2
Which db2 version and fixpak on which operating system?
We have DB2 v8.1.1.96 FixPak 10 on AIX 5.2
What is the exact error that you get ?
I got SQLCODE=-727 and SQLSTATE=56098

I think the table name can not be used as parameter in a prepare
statement? Is that correct?

Thanks

D.

Jul 7 '06 #3
young wrote:
Hello all,

I would like to use same SQL statement in my SQC program for several
tables
I tried something like that:

- sql_sts="SELECT col1, col2 FROM ?"
- EXEC SQL PREPARE dsql FROM :sql_sts;
- EXEC SQL DECLARE cTab CURSOR WITH HOLD FOR dsql;
- EXEC SQL OPEN cTab USING :tabName;
EXEC SQL FETCH cTab;
- EXEC SQL CLOSE cTab;

where tabName is a parameter, and it does not work!
Could I use a host variable like this way in my SQC?
Thanks for your help
You can't do that. If you have static embedded SQL, then DB2 would attempt
to compile the statement. And that's impossible if DB2 doesn't know the
table it is working with. If you have dynamic embedded SQL (it looks that
way to me), you don't really need a parameter marker there. Just build the
SQL statement with the actual table name using sprintf() or other means.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Jul 11 '06 #4

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

Similar topics

6
1921
by: Geoff Berrow | last post by:
The host of one of the domains I manage has installed 4.3.11-dev and as a result file uploads no longer work with Internet Explorer. Worth keeping an eye out for. In the meantime I now need to ask why they have installed a development version on a production server... -- Geoff Berrow (put thecat out to email) It's only Usenet, no one dies.
6
7327
by: Marvin Libson | last post by:
Hi All: I am running DB2 UDB V7.2 with FP11. Platform is Windows 2000. I have created a java UDF and trigger. When I update my database I get the following error: SQL1224N A database agent could not be started to service a request, or was terminated as a result of a database system shutdown or a force command.
4
13054
by: Tim.D | last post by:
People, I've ventured into the wonderful world of Stored Procedures. My first experience has been relatively successful however I am stuck on using host variables to specifiy actualy table or column names in a FROM clause. After many hours or reading all manner of manuals I've discovered it appears this is not possible and that in order to so I need to further venture into dynamic SQL. My present procedure is based on all static SQL...
3
6817
by: claus.hirth | last post by:
Does the term 'host variable' cover a variable locally declared in a SQL-PL stored procedure? I am asking this question in the context of the SELECT INTO statement.
10
2170
by: Extremest | last post by:
I know there are ways to make this a lot faster. Any newsreader does this in seconds. I don't know how they do it and I am very new to c#. If anyone knows a faster way please let me know. All I am doing is quering the db for all the headers for a certain group and then going through them to find all the parts of each post. I only want ones that are complete. Meaning all segments for that one file posted are there. using System;
2
5601
by: Frank Swarbrick | last post by:
I'm just learning about embedded SQL, so be gentle... My basic question is, if I use a fixed length host variable for a column defined as VARCHAR, will trailing spaces be removed (or not) upon INSERT or UPDATE of this column? I tried it, and it appears they are *not* stripped. However, the Programming Client Applications manual leads me to believe that the spaces should be stripped. A quote from that manual: -------------------------...
1
2556
by: young | last post by:
Hello all, I tried to do a sqc program with a "SELECT column INTO :host_variable FROM table" statement and got an error SQL4942N="The statement selects an incompatible data type into host variable" My column is Decimal(6,2) data type definition, and my host variable is defined as float I work on AIX 5.2 with DB2 8.2 Any idea?
1
2120
by: Ergates | last post by:
I'm sure I'm just being thick, but I just can't get the following to work. I have loaded an XSD file into an Oracle xmltype table (called xsd_table here). The xsd looks roughly like this: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="BASE_ELEMENT"> <xs:complexType> <xs:sequence> <xs:element name="MID_ELEMENT_A"> <xs:complexType>
1
8250
by: vineetbindal | last post by:
Hi All, I am new to silverlight and i am following a tutorial. In order to connect to database in silverlight application i need to add a referance to a service. which gives me an error that the contract is not found. I had installed the iis after .net framework 3.5 but i have followed and done all the instructions given at microsoft's website. please help me.
0
7993
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
7920
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8401
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...
0
8404
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8054
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,...
1
5867
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3900
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...
1
2418
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
1
1510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.