Id: | 13081 |
Product: | finPOWER Connect |
Type: | NEW |
Version: | 2.03.01 |
Opened: | 07/07/2015 |
Closed: | 13/07/2015 |
Released: | 07/08/2015 |
Job: | J015873 |
SQL Where Builder; AppendInSubQuery did not allow ORDER BY
In the finPOWER Connect Business Layer, the ISSqlWhereBuilder, AppendInSubQuery method never added the ORDER BY of the sub-query. Note, this was by design as SQL Server will error with an IN sub-query that has an ORDER BY.
However, this has been relaxed as SQL Server does allow an IN sub-query that has an ORDER BY when there is also a TOP clause.
So, with a TOP clause this is valid:
SELECT * FROM [Account] WHERE [Account].[Pk] IN (SELECT TOP 2 [AccountPk] FROM [AccountClient] WHERE [AccountClient].[AccountPk] = [Account].[Pk] ORDER BY [AccountClient].[ClientPk]) ORDER BY [AccountId]
Remove the TOP clause and the ORDER BY shouldn't be included:
SELECT * FROM [Account] WHERE [Account].[Pk] IN (SELECT [AccountPk] FROM [AccountClient] WHERE [AccountClient].[AccountPk] = [Account].[Pk]) ORDER BY [AccountId]