Insert Data Into Temp Table with Query

后端 未结 8 1956
春和景丽
春和景丽 2020-12-12 12:43

I have an existing query that outputs current data, and I would like to insert it into a Temp table, but am having some issues doing so. Would anybody have some insight on h

相关标签:
8条回答
  • 2020-12-12 13:24

    This is possible. Try this way:

    Create Global Temporary Table 
    BossaDoSamba 
    On Commit Preserve Rows 
    As 
    select ArtistName, sum(Songs) As NumberOfSongs 
     from Spotfy 
        where ArtistName = 'BossaDoSamba'
     group by ArtistName;
    
    0 讨论(0)
  • 2020-12-12 13:28

    Personally, I needed a little hand holding figuring out how to use this and it is really, awesome.

    IF(OBJECT_ID('tempdb..#TEMP') IS NOT NULL) BEGIN DROP TABLE #TEMP END
            SELECT *
                INTO #TEMP
                FROM (
                The query you want to use many times
                ) AS X
    
    SELECT * FROM #TEMP WHERE THIS = THAT
    SELECT * FROM #TEMP WHERE THIS <> THAT
    SELECT COL1,COL3 FROM #TEMP WHERE THIS > THAT
    
    DROP TABLE #TEMP
    
    0 讨论(0)
提交回复
热议问题