次のテーブルがあります。
RecordID
101
102
103
104
105
106
TableOne
101
102
103
104
TableTwo
TableThree
101
102
他のテーブルに含まれていない RecordsID 行を削除する必要があります。テーブル TableOne、TableTwo、TableThree の 1 つが空である場合があり、その場合はレコードを削除しないでください。
結果表は次のようになります。
RecordID
101
102
空のテーブルのため、INNER JOIN を使用できません。関数でこれらのコードを使用しているため、レコードを持つテーブルのみを含む動的 SQL ステートメントを作成して実行することはできません。
私は IF ステートメントでこれを行うことができましたが、私の実際の状況では、チェックするケースが多く、結合するテーブルが多く、結果として多くのコードの重複が発生しています。
そのため、CROSS APPLY を使用して、これをより賢く、よりクリーンにする方法はないかと考え始めました。