私たちはこのようなことをしています
create view v1
as
select 'tab1' as table_name , * from table1
union All
select 'tab2' as table_name , * from table2
union All
select 'tab3' as table_name , * from table3
次にSPで、
declare @var = function_gettablename()
select * from v1 where table_name = @var and datetoload = <ActualDate>
function_gettablename() = gives the table name based on parameters
datetoload = すべてのテーブルで相互に排他的なクラスター化されていないインデックス付きの列。つまり、1 つのテーブルでのみ 1 つの日付を使用できます。
ここでの問題は、実行計画であるということです。 @var を使用すると、必要なテーブルではなく、3 つのテーブルすべてがビューにクエリされます。
ユニオンオールを実行してからフィルターを適用するのではなく、フィルターを適用してからユニオンオールを適用する方法はありますか。
ありがとうAB