ビュー、インライン関数、派生テーブル、およびサブクエリに set 操作が含まれている場合、FOR XML 句は無効です。この問題を解決するには、派生テーブルの構文を使用して set 操作が含まれている SELECT をラップしてから、FOR XML を適用します。
Click to search this error in Google
English version
The FOR XML clause is invalid in views, inline functions, derived tables, and subqueries when they contain a set operator. To work around, wrap the SELECT containing a set operator using derived table syntax and apply FOR XML on top of it.