storing a sql query a more efficient way?

i'm using visual basic with

i'm using asp to perform a long query.  it spans about 30 lines and i want the code to be clean.  i am trying to store this as a string.

what is the best way to do this?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

As a stored procedure in the database. =0)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
...or if that is not an option and you just want something that looks cleaner, you can use a stringbuilder

' Import system.text
            Dim sb As StringBuilder = New StringBuilder
            sb.Append("some text ")
            sb.Append("some more text ")

which looks much cleaner than concat string
dim str as string
str = "some text "
str &= "some more text "
or try toad and write your query in the editor and use the export to vb key. ;-)
I usually build a template first and then replace template variables with real ones:
for example:
string template = "select #fld1, #fld2 from #Table where #fld3='#val1'"

and then
template = template.Replace("#fld1", "RealField1");
template = template.Replace("#fld2", "RealField1");
template = template.Replace("#fld3", "RealField3");
and so one.

You might wannna break your query like this

strSQL = "SELECT columnA, " & _
              "            columnB, " & _
              "            columnC, " & _
              "FROM    tableA   , " & _
              "             tableB     " & _
              "WHERE  columnA = columnB " & _
              "ORDER BY columnA"


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.