subquery - SQL server Temp table with joins inside other select -
i have following structure:
create @temp select ...inser...into @temp ... (select ... @temp join tbla ... ) union (select ... @temp join tblb ... )
after build above table need able perform where, joins, ...
something like:
select ... (above statement) join .... where....
i don't know how of if @temp,joins, union... can inside other select.
or thing can create @temp2 inserting first statement result , work other join,where... ?
update 1:
i trying:
with cte (query returned columns) (same query using build @temp before) (select ... cte join tbla where...) union (select ... cte join tblb where...)
but im stuck @ same point in how perform other joins, where... above total result
actually can without temp-table:
with mycte [ ( column_name [,...n] ) ] ( here define query )
and after select use cte
select ... mycte join .... where....
about cte can read here after update
select fields mycte join table1 union select fields mycte join table2
without brackets in query
Comments
Post a Comment