Ozzone wrote:
Often I notice many users writing a SQL string like the following:
sql = "SELECT * FROM <tblName> "
sql = sql & "WHERE X = " & <variablename> & ""
sql = "SELECT * FROM <tblName> WHERE X = " & <variablename> & ""
seems the better method.
The use of the line continuation with the second method is useful as
others have pointed out.
I use a combination of the two. I like the first method for
particularly long statements because I can add comments indicating what
each line is or why I've chosen a particular function. Also, depending
on choices a user makes in my GUI, there maybe a requirement for more or
less tables to be pulled into the mix.
The line continuation also has a limit to the number of times you can
use it. I forget exactly how many. In my current project, the Oracle
SQL I'm writing, which consists of up to four main select statements
"union all'ed" together, with some of the from clauses containing
lengthy in-line queries which are themselves multiple union select
statements can add up to a huge number of characters. Haven't counted
them yet, but some of the larger statements, when pasted to MS Word span
15 pages in Tahoma 8 font.
With such monstrous statements, the first method, along with comments
really helps you realize where you are.
BTW, is "concatenate" the correct term here?
--
Tim
http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "What's UP, Dittoooooo?" - Ditto