Re: Dynamic Sql Q (esqlc)
Posted in 1996
Jeff Pickett wrote:
>
> I am looking some help writing dynamic sql in esqlc. I have been
> trying to use the manuals for direction, but I still can't get it
> to work. Allow me to explain the scenario.
>
> I want to dynamically form an insert statement, prepare it once,
> and then execute it multiple times with different data. So it
> seems to me that this is a job for dynamic sql....
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
No! Feel free to use dynamic SQL if you want but there is absolutely
no need to use it here. In fact, in this case, dynamic SQL simply
makes the work a lot more obscur.
In ESQL/C, INSERT statements can be coded simply as:
EXEC SQL
INSERT INTO table (col1, col2,...) VALUES (:var1, :var2,...);
For example, this statement could be put in a loop where var1, var2,...
have different values each time or it could be put in a function
where var1, var2,... are passed as argument.
You would need dynamic SQL if the type of statement (INSERT, UPDATE,...)
or table name or column names were not known until run-time.
Hope this help clarify dynamic SQL.
Guy