If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Informix > query needs to use dynamic database:table name

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-04-09, 13:30
al91206 al91206 is offline
Registered User
 
Join Date: Mar 2009
Posts: 6
query needs to use dynamic database:table name

Hi,

We have an informix environment where we have several customer databases:

Customer001
Customer002
Customer003

Obviously this is not a great way to do things, and we have a long-term project to combine them into 1 database, but for the meantime I need to come up w/ sql to get information out of each one for a report.

select item
from customer001:item <-- this is where I need the dynamic "db selector"

Any help is appreciated.

Thanks,

Al in SoCal
Reply With Quote
  #2 (permalink)  
Old 03-05-09, 13:50
artemka artemka is offline
Registered User
 
Join Date: May 2004
Location: New York
Posts: 248
why don't you do something like a for loop in a shell script

file_name contains the names of the databases

for i in `cat file_name'
do
dbaccess $i <<!!
select * from tablename
!!
Reply With Quote
  #3 (permalink)  
Old 03-17-09, 16:12
ceinma ceinma is offline
Registered User
 
Join Date: Apr 2007
Location: Jundiai / SP - Brasil
Posts: 311
After version 11.50 this is possible in Stored Procedures, but unfortunately I never see this in sql statement .

copied from Release notes of 11.50 UC1

Quote:
New Support for Dynamic SQL Statements in SPL Routines
In earlier versions of the Informix SPL language, the form of SQL statements in a UDR was known when the SPL routine was written. Users can now specify queries dynamically at runtime in SPL routines, using the EXECUTE IMMEDIATE and PREPARE statements to execute dynamically constructed SQL statements and to define and manage cursors and prepared objects with the DECLARE, OPEN, FETCH, CLOSE and FREE statements.
For some of these Dynamic SQL statements, the SPL syntax is a subset of the existing ESQL/C syntax, but character expressions that evaluate to SQL statement text are now supported by PREPARE and EXECUTE IMMEDIATE statements in SPL routines. In addition, Boolean conditions in SPL statements can specify SQLCODE as an expression that returns the SQLCA status from the most recently executed SQL statement.
This feature increases the flexibility of UDRs written in the SPL language, and simplifies the migration to IDS of stored procedures and applications written for other database servers that support Dynamic SQL operations. This feature is documented in the Guide to SQL: Syntax.
__________________
________________________________________
César Inacio Martins
Jundiai / SP - Brasil
http://www.imartins.com.br/informix - em Português
http://www.imartins.com.br/informix - English (translated by Google).
________________________________________

Last edited by ceinma; 03-17-09 at 16:17.
Reply With Quote
  #4 (permalink)  
Old 03-19-09, 19:02
al91206 al91206 is offline
Registered User
 
Join Date: Mar 2009
Posts: 6
Thanks for the info

Thanks for the info - I'll be checking the guide and get back to everyone if we get this figured out.
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On