How To: Do multi-line string vars?

  • Thread starter Thread starter Scott McNair
  • Start date Start date
S

Scott McNair

I'm running into a situation where I want to take a multi-line SQL
statement and include it as a string in my code. I know that I can do
something like

strSQL = "SELECT * "
strSQL &= "FROM tbl.dbo.MyTable, "
strSQL &= " tbl.dbo.MyTable2 "
strSQL &= "WHERE MyTable.ID = MyTable2.ID "
strSQL &= "ORDER BY Date DESC"

but is there a way to do something like

strSQL = ::BOF::
SELECT *
FROM tbl.dbo.MyTable,
tbl.dbo.MyTable2
WHERE MyTable.ID = MyTable2.ID
ORDER BY Date DESC
::EOF::

?

I know it sounds like a petty issue, but some of these SQL statements
are scores of lines long, and are subject to overhaul from time to
time... if there was a way to do what I'm looking for, I could save some
5-10 minutes of formatting headaches. I'm afraid I know the answer
already (as "No") but I figured it wouldn't hurt to ask.

Thanks,
Scott
 
Ho Scott

I may not have the exact answer you are looking for, but a possible
alternative

Use the StringBuilder class ,
This will give you 2 great abilities
1. You can change the lines fairly quickly and easy
2. Formatting, very handy feature

Exp.
StringBuilder sbSql = new StringBuilder() ;
sbSql.Append("SELECT * ") ;
sbSql.AppendFormat("FROM {0}, ","tbl.dbo.MyTable") ; //just to illustrate
sbSql.Append(" WHERE MyTable.ID = MyTable2.ID ")

This may help in inserting, altering strings as well as passing dynamic
related information
Henk
 
2 suggestions:

1) write the SQL-String in an external file and read it in at runtime
2) use stored procedures in the DB ;-)

Jon
 
Back
Top