473,473 Members | 2,151 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Selecting from a Dynamic Table in SQL

4 New Member
Hi all,

I have created a procedure that selects from a table based on the value of another table concatenated with some text.

So this code below should select all from the table FL_TIME_DIM(value)

However I get an error that states
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "DECLARE" was found following "RE V_SQL
VARCHAR(64)". Expected tokens may include: "<psm_semicolon>". LINE
NUMBER=1. SQLSTATE=42601


Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE TEST_1
  2. DYNAMIC RESULT SETS 1
  3. LANGUAGE SQL 
  4. INHERIT SPECIAL REGISTERS 
  5. BEGIN 
  6. DECLARE V_SQL VARCHAR(64) 
  7. DECLARE V_TABLE VARCHAR(256) 
  8. DECLARE C_SQL CURSOR WITH RETURN FOR S_SQL 
  9. SET V_TABLE = 'concat(''FL_TIME_DIM'',(select Value from table ))' 
  10. SET V_SQL = 'SELECT * FROM '||V_TAB||'FOR READ ONLY' 
  11. PREPARE S_SQL FROM V_SQL 
  12. OPEN C_SQL 
  13. END;
If anyone could help me out it would be much appreciated.

Thanks,
apple
Oct 3 '08 #1
4 2387
appletastic
4 New Member
Alright for the above code I added semicolons to the end of each line and that seemd to have solved that problem but arose another, now I get

SQL0104N An unexpected token "(" was found following "SELECT * FROM concat".
Expected tokens may include: "WHERE". SQLSTATE=42601


I guess the issue is concatenating the table name and value together.

Any Ideas??

Thanks,

apple
Oct 3 '08 #2
sakumar9
127 Recognized Expert New Member
I am not sure if you are using CONCAT propoerly.
Oct 5 '08 #3
sakumar9
127 Recognized Expert New Member
# SET V_TABLE = 'concat(''FL_TIME_DIM'',(select Value from table ))'

You cannot have any SQL like SELECT * FROM contact('a', 'b').

Instead, you can have these values concated before the SELECT itself and try.
Oct 5 '08 #4
appletastic
4 New Member
# SET V_TABLE = 'concat(''FL_TIME_DIM'',(select Value from table ))'

You cannot have any SQL like SELECT * FROM contact('a', 'b').

Instead, you can have these values concated before the SELECT itself and try.
Thanks sakumar9,

Makes sense to Concat first, but I'm not exactely sure on how to do that. Any ideas, would be very helpful.

apple
Oct 6 '08 #5

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

Similar topics

4
by: Franco Fellico' | last post by:
Hi everybody. Suppose to have a table dinamically created in a form where I show some information of a set of row selected in a db-table: ....... while($row = mysql_fetch_array($result)) {...
11
by: Ian Rastall | last post by:
In a project mentioned in another thread, I'm trying to get some dynamic data to work. In this discography, you can click on an album name, and the title of the album and its tracks will appear on...
2
by: John | last post by:
Hello, I have a table called BUILDREQUESTS which I want to select from, depending on the project ID of each record. The Project ID field is indexed. (A) This query runs almost instantly: ...
4
by: manning_news | last post by:
Using SQL2000. How do I format my select statement to choose one out of 24 different tables? Each table is slightly different and I was hoping I could use one select statement and format it...
1
by: R. P. | last post by:
Anybody knows a way to produce output from a SELECT statement on a single line, instead of each hit on a separate line? Here is what I mean: let's say I have a table listing families, one per...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
1
by: Nathan Sokalski | last post by:
When testing a form of mine which uses RequiredFieldValidators that have the Display property set to "Dynamic" the ErrorMessage property is automatically removed when an entry is completely typed...
7
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always...
2
by: Tymbow | last post by:
I'm building a web application that is analogous to the Windows XP file explorer in function. The left column contains a TreeView, and the right column a DataGrid populated by selecting TreeView...
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
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.