Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old October 3rd, 2008, 09:50 PM
Newbie
 
Join Date: Oct 2008
Posts: 4
Default Selecting from a Dynamic Table in SQL

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
Reply
  #2  
Old October 3rd, 2008, 10:06 PM
Newbie
 
Join Date: Oct 2008
Posts: 4
Default

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
Reply
  #3  
Old October 5th, 2008, 05:11 PM
sakumar9's Avatar
Expert
 
Join Date: Jan 2008
Location: Bangalore
Age: 26
Posts: 127
Default

I am not sure if you are using CONCAT propoerly.
Reply
  #4  
Old October 5th, 2008, 05:15 PM
sakumar9's Avatar
Expert
 
Join Date: Jan 2008
Location: Bangalore
Age: 26
Posts: 127
Default

# 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.
Reply
  #5  
Old October 6th, 2008, 02:57 PM
Newbie
 
Join Date: Oct 2008
Posts: 4
Default

Quote:
Originally Posted by sakumar9
# 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
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles