SQL Prompt Wrongly Alias'ing order by clause
GregDodd
Posts: 12 Bronze 2
in SQL Prompt
When you have a table joined to itself and you alias the 2nd table but not the first, SQL Prompt formats the order by clause to use the Aliased tablename, overwriting the chosen filename.
e.g.:
e.g.:
SELECT Product.ProductCode
,MainProduct.ProductCode
FROM Product
INNER JOIN Product AS MainProduct
ON MainProduct.ProductItemID = Product.MainProductID
ORDER BY Product.ProductName
When you format, it becomes:
When you format, it becomes:
SELECT Product.ProductCode
,MainProduct.ProductCode
FROM Product
INNER JOIN Product AS MainProduct
ON MainProduct.ProductItemID = Product.MainProductID
ORDER BY MainProduct.ProductName
The field names in the select statement correctly pick which table they are coming from (the aliased or non-aliased), but the order by clause always picks the aliased table.
If I alias both tables then it doesn't have a problem (Even if the alias is the same as the table name):
The field names in the select statement correctly pick which table they are coming from (the aliased or non-aliased), but the order by clause always picks the aliased table.
If I alias both tables then it doesn't have a problem (Even if the alias is the same as the table name):
SELECT Product.ProductCode
,MainProduct.ProductCode
FROM Product AS Product
INNER JOIN Product AS MainProduct
ON MainProduct.ProductItemID = Product.MainProductID
ORDER BY Product.ProductName
Tagged:
Answers
I'm not able to reproduce it with version 9.2.8.6358. Please upgrade and test again.
Tianjiao Li | Redgate Software
Have you visited our Help Center?
Then write the following script:
Then when I format it I get MainProduct.ProductName in the order by clause
I've reproduced the issue! Thanks very much for your help.
It's logged as SP-7229 in our internal bug tracking system. Please keep an eye on the release note for the fix!
Tianjiao Li | Redgate Software
Have you visited our Help Center?