Give Format SQL the ability to convert X.Field1 AS NewFieldName format to FieldName = X.Field1
We have a lot of legacy code that is written as
SELECT Field1 as Name1, Field2 Name2 FROM Table X
(Sometimes they use AS when setting the alias, othertimes they do not).
I would love the ability to convert this to
SELECT
Name1 = X.Field1
, Name2 = X.Field2
FROM Table X
Both having the ability to switch between Name = Value and Value AS Name and to auto add the alias to all fields.
This feature was released in version 7.3 of SQL Prompt.
If there are any missing features please let us know by creating a new suggestion.
Kind Regards,
The Prompt Team
-
AdminAaron Law (Admin, Redgate) commented
Hi Blaž,
It's on the Format->Actions page of the SQL Prompt options: http://imgur.com/a/WfNcI
-
Blaž Dakskobler commented
Aaron, where exactly is this new format action in the GUI?
-
Phil Parkin commented
I was just about to create this suggestion. Glad I'm not the first – this would be a fantastic feature. I'd suggest making the 'AS' optional too.
-
Rick commented
Unfortunately there are 8 options. The most obvious, [name] vs 'name', is absent.
But what a cool idea. Especially the add-all/remove-redundant. -
Andrew Higgins commented
After a little more searching, I found two similar suggestions: these are smaller in scope but are asking for subsets of this feature.
-
Andrew Higgins commented
There are six different ways to alias a column that I've seen used:
;WITH cte AS (SELECT 1 AS MyColumn)
SELECT
MyColumn AS MyAlias,
MyColumn AS 'MyAlias',
MyAlias = MyColumn,
'MyAlias' = MyColumn,
MyColumn MyAlias,
MyColumn 'MyAlias'
FROM cteCan you include an option in the Format SQL command that allows you to choose a preferred alias style?
"Format SQL" would then convert all aliases to the preferred style.As a bonus feature, you could also include an option to add aliases to all columns, or remove all redundant aliases.