Skip to content Skip to sidebar Skip to footer

Variable Table Or Column Names

INFORMIX-SQL or any other SQL-based DB: Suppose I have an app where depending on the value of some columns, example: company.code char(3) {abc} company.branch char(2) {01} Can I

Solution 1:

Only in a language which can manipulate character strings and handle Dynamic SQL. It has to create the statement on the fly.

You can only use placeholders in queries for values, not for the structural elements of the query such as the table name or column name.

Solution 2:

Only if you use dynamic sql. It's like you build sql code in your app, then use something like execute immediate.

sprintf(cdb_text1, "create table %s (field1 char(3));", usr_db_id);
EXECSQLexecute immediate :cdb_text;

If you use dynamic sql, it's bad because of sql injections.

Post a Comment for "Variable Table Or Column Names"