Incorrect syntax near the keyword 'FROM' when using MS SQL Server 2012

Business Partner and Product fields (mentioned in the sort set) have default lookups. That is why they produce the TRIM function in the resulting SQL.