Here is the concept of what I am trying to do.
I basically have two sets of data, one for the current info and one for archived info. I need to union them to show them all in one list.
My query is much more complicated than this but for simplicities sake I’ve just posted the general idea of what I need to do.
How would I get this to work for me? Any help is greatly appreciated.
(
with m1 as
(
select --distinct
pfa.FacilityID
from PatientFormCompleted
)
select * from m1
left join other tables
)
union all
(
with m1archive as
(
select --distinct
pfa.FacilityID
from PatientFormArchive
)
select * from m1archive
left join other tables
)
Likely this will be closed (voted, not downvoted, myself BTW) but after your edit, you did put some effort in the question, so here goes
You can use multiple
CTE‘s but with the constraint thatWITHgets writtenPlease note that you should not use
SELECT *but be specific in what columns you’d like to return.SQL Statement