|I have a method that takes a SQL query and a file name, then converts that query into an XML-based Excel file. Works great. The code gets the schema of the query, and uses the column names to generate the column headers in Excel. This, too, works great.
The problem is aliasing the columns into the headers that I want. I am using this notation:
"First Name" = view.MeaninglessColumnNameImposedBySystem1,
"Last Name" = view.MeaninglessColumnNameImposedBySystem2,
"Address 1" = view.MeaninglessColumnNameImposedBySystem3,
FROM LongViewName AS view
Whether I have one column or 50, the query takes several minutes to run; the more data, the longer it takes. If I were to use
SELECT *, with no aliasing, I can return the data in a few seconds, regardless of how many rows are returned.
I have also tried
view.MeaninglessColumnNameImposedBySystem1 AS [First Name], which does not speed up the results.
Presumably, this is an optimization issue where
* lets SQL make assumptions that it cannot when each column is aliased. Any suggestions on what I can do with the query to speed things up?