Dynamic column names in UPDATE
Posted in 1994
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
Hello folks, My first mail into this interesting newsround! I am a beginner inj Informix 4GL and I am using a table with a funny contents, namely two numbers debit and credit for each month of a certain year. We wanted to have these numbers in one record. ( We use debitjan,creditjan ... ) Now when they are updated, I receivethe number of the month (1..12) and I have to covert this into the column name. I thought I found a fantastic way of doing this using the PREPARE and EXECUTE commands, but this doesn't work for variable names of columns, only for variable values for those columns. FUNCTION Foo ( ecriture ) DEFINE ecriture RECORD LIKE ecrit_analy.*, stringUpdate CHAR(500), monthName CHAR(3), debitCol CHAR(8), creditCol CHAR(8) CASE MONTH(ecriture.periodcp) WHEN 1 LET monthName = "jan" WHEN 2 LET monthName = "fev" ... WHEN 12 LET monthName = "dec" END CASE LET debitCol = "debit",monthName LET creditCol = "credi",monthName LET stringUpdate= "UPDATE plan_compt ", "SET cumdeban=cumdeban + ? ,", " cumcrean=cumcrean + ? ,", " ? = ? + ? ,", " ? = ? + ? ", "WHERE ...condition PREPARE queryUpdate FROM stringUpdate EXECUTE queryUpdate USING ecriture.montdebi,ecriture.montcrdi, debitCol,debitCol,ecriture.montdebi, creditCol,creditCol,ecriture.montcrdi END FUNCTION I realise what I did was a bit crazy, but it could work if prepare was only a kind of parser. Does anybody know a way to reach this kind of dynamic access to tables ( variable column names ). Eric Van der Hulst Siemens-Nixdorf evdh@csl.sni.be