A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Hi @coool sweet ,
Welcome to microsoft TSQL Q&A forum!
I am also confused: why do you need a separate sql statement? For your question, the alternative is to use cte, but as ErlandSommarskog mentioned, the efficiency of temporary tables is actually higher than cte.
Please also check:
;with cte as
( select fb.*,sls.order_date,sls.next_date,DEFAULT_STATUS
from dbo.ORDER_HIST SLS with(nolock)
join #FB_PLAN_START_STOP_V2 fb with(nolock)
on fb.number = sls.number
where sls.SNAPSHOT_DATE > END_DATE and CATEGORY = '01. CURR/PP')
select into #POST_PAYMENTS
from cte SLS with(nolock) join dbo.sss SLM with(nolock)
on sls.number = SLM.number
where sls.cnt = 1
;with cte2 as(select fb.*,sls.order_date,sls.next_date,DEFAULT_STATUS
from dbo.ORDER_HIST SLS with(nolock) join #FB_PLAN_START_STOP_V2 fb with(nolock)
on fb.number = sls.number
where sls.SNAPSHOT_DATE < START_DATE and CATEGORY = '01. CURR/PP')
select into #PRE_PAYMENTS
from cte2 SLS with(nolock) join dbo.sss SLM with(nolock)
on sls.number = SLM.number
where sls.cnt = 1
If you have any question, please feel free to let me know.
Regards
Echo
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.