SQL for Smarties | SQL Programming Style | Trees and Hierarchies in SQL | SQL Puzzles and Answers | Data and Databases


Monday, July 03, 2006

Dynamic SQL within Procedure - String Continuation/Builder

SQL Apprentice Question
I am trying to build a SQL statement dynamically for execution within a
procedure, using PREPARE ... OPEN.


SET v_sql = ' SELECT a,b,c,d,e, .....x,y,z FROM table1, table2 WHERE
a = v_1...and so on FOR READ ONLY';


What is used for continuation if I want to break the variable v_sql out
into lines so one can read it?


SET v_sql = ' SELECT a,b,c,d,e, .....x,y,z (what goes here?)
FROM table1, table2 (and here?)
WHERE a = v_1...and so on (and here?)
FOR READ ONLY';



Celko Answers
>> I am trying to build a SQL statement dynamically for execution within a procedure, ..<<


Do not write code like this. It says that your design is so bad that a
random future stranger can do a better job at run-time that you did
with all the specs and weeks of coding. You say that you don't know or
care about SQK injection, etc. Justr sloppy coding


>> What is used for continuation if I want to break the variable v_sql out into lines so one can read it? <<


Why are you worred about display instead of performance anyway? This
is like asking a furniture newsgroup for the best rocks for smashing
screws into wood. The quick answer in "Granite!" but the right answer
is "uses a screw driver" instead.

No comments: