2000行を超えるコードを持つストアドプロシージャがありますfrom clause
。条件に基づいてテーブル名を変更する必要があります。列名は両方のテーブルで同じままです。
例えば:-
Declare @condition char(1)
set @condition=(Select close_flg from log
where last_run_dt >=
(Select cur_dt from dt)
)
--If @condition is 'A' then below sql will execute
Select a.columnA,
Case
when @condition='A' then 'D'
Else 'M'
END,
b.ColumnC
from TableA as a
inner join TableB as b
on a.Column=b.Column
@conditionが'B'の場合、SQLを次のように変更する必要があります(内部結合のみが異なり、selectクエリのすべての列は同じです)
Select
-- the same columns as above
from TableC as c
inner join TableD as d
on c.Column=d.Column
重複コードを減らすためにSQLを汎用化したいのですが、そうすることも可能ですか。
ありがとう