You are here:

Ingres/update with variables

Advertisement


Question
I'm writing an UPDATE statement where I must include the name of the column which I want to update in a host variable. That works in the left part of the SET clause, but in the right, the program 'reads' the character chain (the name of the column), not its value, as I want.

UPDATE :arr_tablas.tabla                      
SET :w_ref_col= :w_ref_col + :w_maximo
WHERE cod= :w_max_cod  

w_ref_col is a varchar variable and the column is  integer.

Can you give me one idea about this? Thanks.  

Answer
Hello,

I suppose your SQL is in a C programm (embeded SQL) or ABF. If you look in the R3 doc PDF files and search for "sql prepare" string, you'll find what you want, I think.

Also look at sql prepare, describe and so on in the doc. Those SQL order will permit you to execute a query formatted in a variable, so both value and column name can be dynamic.

The variable content is the query Ingres will execute and should look like this :

UPDATE table_name                
SET column_name = column_name + value
WHERE cod= value

where table_name, column_name and value
are provided by the variables
:arr_tablas.tabla, :w_ref_col, :w_maximo and :w_max_cod.

Hope this clear, and hope this help you. Let me know if not.

Cheers,
Jean-Pierre

Ingres

All Answers


Answers by Expert:


Ask Experts

Volunteer


Jean-Pierre Zuate

Expertise

Any questions about database Ingres (owned by Computer Associates then Ingres Corp) : - Ingres 6.4 - OpenINGRES from 1.0 to 2.0 - IngresII from 2.0 to 2.6 - Ingres R3, Ingres 2006 (Open Source version) - Ingres 9.x, Ingres 10.x - All tool around Ingres : ABF, Report Writer, Replicator, OpenROAD (3.5 to 2006), Ingres/NET Ingres/STAR, ...

Experience

16 years of computing experience as :
- AS400 programmer
- AIX / Ingres administrator and developer (OpenROAD and korn shell)
- Ingres DataBase Administrator
- Ingres expert - Data modelisation - ETL - Reporting - Many of Computer Associates sofwares - ITIL / CMDB / Change Management

Organizations
http://lafageconseil.fr

Education/Credentials
Computing bachelor (1989)

Past/Present Clients
More than 100 customers during my 6 years of CA has an Ingres consultant, all around France and Africa (Togo, Cameroon, Morrocco, ...)

©2012 About.com, a part of The New York Times Company. All rights reserved.