CTE chỉ tốt cho một truy vấn, nhưng có vẻ như bạn có thể sử dụng CTE trong mỗi truy vấn:
WITH ds AS
(
Select a, b, c from test1
)
Select * from ds (the result set of ds, am exporting this to csv)
WITH xy AS
(
select d,e,f from test2 where (uses conditions from test1)
)
Insert into AuditTest
(
Select * from xy
)