I know this might be a bad example, but my question in this case has more to do with the best / most efficient way to deal with a StringBuilder rather than my SQL query itself, so please bear with me...
As an example to show what I'm looking to achieve, suppose I had a large list of tables in a database, all of which had the same structure, and I wanted to create a query to pull data from all of them in one single query.
The way I thought of doing this was:
Dim MyTables As List(Of String) = {"Table1", "Table2", "Table3" ... "TableN"}.ToList
Dim SQLQuery As New StringBuilder
For Each tbl As String In MyTables
SQLQuery.AppendLine("SELECT [col1], [col2], [col3] FROM " & tbl)
SQLQuery.AppendLine("UNION")
Next
Again, ignoring whether this is the best way to do that (although I'd love to know if there is a better way, but I don't want the answers to be skewed in that direction - I'm more interested in knowing how to deal with the StringBuilder efficiently in this case).
Given the way I do this, my StringBuilder is going to have an extra UNION & vbCrLf
at the end of it that I need to remove - I know I could do it using something along the lines of:
SQLQuery.Remove(SQLQuery.Length - ("UNION" & vbCrLf).Length, ("UNION" & vbCrLf).Length)
And, of course, I could make that more efficient, but my question basically is what is the best / most efficient way to create such a stringbuilder using a loop where the "concatenator", as such, is a fairly large string that would be appended to the end if you did it my way?
I know this question was written in VB, but I'm equally as comfortable with answers in C#. THANKS!!!