I have a series of SQL statements that I need to put into one result set.
Here's a part of the SQL:
APPT_DATE INTO #DEMO
LEFT OUTER JOIN CUST_NAME ON CUST_NAME.APPT_ID = CUSTOMER.APPT_ID
WHERE SERVICE = '12345'
AND NAME LIKE ('%xxxx%')
AND STATUS_C IN (11,21);
DATEDIFF(D,#DEMO.APPT_DATE, EFFECTIVE_DATE) as days into #visits
LEFT OUTER JOIN CUSTOMER1 ON CUSTOMER1.CUST_ID = #DEMO.ID
LEFT OUTER JOIN PROCESS ON PROCESS_ID = #DEMO.PROCESS_ID
WHERE DEPT_ID IN ('51','55','61','65','71','75','81','85'
ANSD EFFECTIVE_DATE > #DEMO.APPT_DATE and
DATEDIFF(D,#DEMO.APPT_DATE, EFFECTIVE_DATE) < 31
ORDER BY NAME ASC;
it continues - but here are the first two statements.
My question is how do I take the #temp tables - do I wrap the SQL into aliased queries and concatenate them into the one script or is there another approach I'm not thinking of?
Thanks in advance