I am writing a query in MSSQL. I am writing a huge logic in CTE, this logic has to be used to insert data into multiple tables. I dont want to write this CTE for every table, want it to be generic for every table.
Example:
with CTE as (Select * from table)
select * into table3 from table1 join cte
select * into table4 from table2 join cte
is it possible to achieve it
I tried to write the insert statement and tried to use the same CTE in generic way