sql server - can I use CTE this way? -


working refactor stored procedure convert heavy sqlxml statements plain sql resultset... it's been difficult..

thinking define multiple cte tables, each reference previous one, this:

;with cte1(column1) (....) cte2(column2) (select column2,...      inner join (select ...          group column3          having column3 in (select column1 cte1)) cte3 (select ...      inner join (select ...          group column4, column5         having column4 in (select column1 cte1)           , column5 in (select column2 cte2)     ) select * cte1, cte2, cte3 

although final select not join each other, can still expect correct resultset

use comma after each cte below:

   ;with cte1(column1) (....) , cte2(column2) (select column2,...      inner join (select ...          group column3          having column3 in (select column1 cte1)) , cte3 (select ...      inner join (select ...          group column4, column5         having column4 in (select column1 cte1)           , column5 in (select column2 cte2)     ) select * cte1, cte2, cte3   

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -