In the sample query below [object_id] and [type_desc] are underlined in green because they're unqualified. SQL Prompt does not automatically add the [p]. aliases and if I manually add them and then format it strips them out. Also, in the first SELECT if I remove the [s] and [pvt] aliases and then format, it puts [s] back but not [pvt]. SQL Prompt 11.0.8 on Azure SQL database.

SELECT
   [s].[name]
 , [pvt].[SYSTEM_TABLE]
 , [pvt].[USER_TABLE]
 , [pvt].[VIEW]
FROM
   (
       SELECT
           [o].[schema_id]
         , [o].[object_id]
         , [o].[type_desc]
       FROM [sys].[objects] AS [o]
   ) AS [p]
PIVOT
   (
       COUNT([object_id])
       FOR [type_desc] IN ([SYSTEM_TABLE], [USER_TABLE], [VIEW])
   ) AS [pvt]
   JOIN [sys].[schemas] AS [s]
       ON [s].[schema_id] = [pvt].[schema_id]
ORDER BY 1;

Chris
0

Comments

1 comment

  • Nathan Hancock

    I’ve run into the same issue with SQL Prompt stripping out aliases. One workaround I found is to manually enforce the formatting style by saving a custom profile. It’s not perfect, but it helps maintain aliases like [pvt] without SQL Prompt rewriting them away every time. Try it!

    Nice day,

    escape road

    Nathan Hancock
    0

Add comment

Please sign in to leave a comment.