user1742174
user1742174

Reputation: 51

Alias error in Excel pivot table sql

I'm pulling data from a database using an Excel pivot table. When I go into Microsoft Query to edit the SQL query, I tried to rename the columns for the pivot table using aliases but keep getting error messages:

SELECT table1.column1 AS "Alias String"

SELECT table1.column1 "Alias String"

SELECT table1.column1 AS my_alias

SELECT table1.column1 my_alias

All of these result in "Syntax Error" messages. I don't want to just rename the columns by hand in the table because when I refresh the data, the names I write get overwritten with the original SQL column names. I'm using Postgresql 8.4 and Excel 2010. What's the syntax I should be using?

Upvotes: 3

Views: 1226

Answers (2)

user1742174
user1742174

Reputation: 51

After some more research, I uncovered that this is actually a glitch in Microsoft Query. This article explains it. After using the workaround described in the article, I was able to rename the column headings, but with extra quote marks. It's a real pain but considering how much time and energy I spent trying to find an answer, I'm willing to accept extra quote marks.

Upvotes: 2

user1340197
user1340197

Reputation: 43

To keep formatting when updating Excel from a SQL database, you need to change the settings in Excel. Write your query and Return Data to Excel. Then on the spreadsheet containing your data, right click, go to Table, then External Data Properties. Make sure Preserve Cell Formatting is ticked. Hope this helps.

Upvotes: 0

Related Questions