The query in the repro section fails with an error that a plan could not be generated. The culprit appears to be the OUTER APPLY for the included columns. if I change it to CROSS APPLY, the query runs, but the result is not correct.The purpose of the query is to script the better part of an index.The simple workaround is to tack on the included columns later.The error happens on all versions from SQL 2005 and up.
Operating System Language
Steps to Reproduce