Using with vs declare a temporary table: performance / difference?

前端 未结 2 504
不思量自难忘°
不思量自难忘° 2020-12-29 07:02

I have created a sql function in SQLServer 2008 that declared a temporary table and uses it to compute a moving average on the values inside



        
2条回答
  •  猫巷女王i
    2020-12-29 07:20

    In addition to what Martin answered

    ;with tempTable as 
    (
        select * from aces.dbo.fEDVisitCounts('ALL', null,DATEADD(DD,-7,'01-09-2010'),
            '04-09-2010',0,130,null,1, 0)
    )
    
    SELECT * FROM tempTable
    

    can also be written like this

    SELECT * FROM 
    (
        select * from aces.dbo.fEDVisitCounts('ALL', null,DATEADD(DD,-7,'01-09-2010'),
            '04-09-2010',0,130,null,1, 0)
    ) AS tempTable  --now you can join here with other tables
    

提交回复
热议问题