Re: Use Variable as Table name in EXEC SQL statements (ESQL/C)
Posted in 1995
We have tried many ways, but have been unable to do this. We access multiple databases across many computers, so we use the 'database@computer:tablename' format alot. Since the 'computer' part of the statement may be different depending on the data item, we often need to vary it. Plus, we want to be able to add more computers in the future if needed, so the programs utilize tables to determine what locations to access. The only way we have found to do this is -- > Please forgive any errors, I always work from a template :-) < --------------------------------------------- char selectStmt[1000] sprintf(selectStmt, "SELECT <fields> from database@%s:tablename where key = \\"%s\\"",location, value) EXEC prepare prepareStmt from selectStmt EXEC declare curStmt cursor for prepareStmt EXEC fetch curStmt --------------------------------------------- A bit of a kludge, but it does work. In your example, you would modify the 'sprintf' statement so that the tablename was set instead of the computername. ------------------------------------------------------------------------- In article <DIt6ns.28n@news.sgp.hp.com>, kok-bin_lee@hp-singapore-om1.om.hp.com (Kok-Bin LEE) wrote: >Hello, > I have heard that ORACLE allows string variable (ESQL/C) to be used to >reference a table in EXEC SQL statements. eg: > > EXEC SQL SELECT BOXNO, SHIPREFNO > INTO :BoxNo, :ShipRefNo > FROM :BOXDETL <<<------- (a C variable) > WHERE :BoxNo=:mBoxNo; > > > Can I do the same in INFORMIX? > >