Preserving ORDER BY in SELECT INTO

前端 未结 8 649
南笙
南笙 2020-11-27 07:18

I have a T-SQL query that takes data from one table and copies it into a new table but only rows meeting a certain condition:

SELECT VibeFGEvents.* 
INTO Vib         


        
相关标签:
8条回答
  • 2020-11-27 08:13

    Try using INSERT INTO instead of SELECT INTO

    INSERT INTO VibeFGEventsAfterStudyStart 
    SELECT VibeFGEvents.* 
    FROM VibeFGEvents
    LEFT OUTER JOIN VibeFGEventsStudyStart
    ON 
        CHARINDEX(REPLACE(REPLACE(REPLACE(logName, 'MyVibe ', ''), ' new laptop', ''), ' old laptop', ''), excelFilename) > 0
        AND VibeFGEventsStudyStart.MIN_TitleInstID <= VibeFGEvents.TitleInstID
        AND VibeFGEventsStudyStart.MIN_WinInstId <= VibeFGEvents.WndInstID
    WHERE VibeFGEventsStudyStart.excelFilename IS NOT NULL
    ORDER BY VibeFGEvents.id`
    
    0 讨论(0)
  • 2020-11-27 08:15

    You cannot do this with ORDER BY but if you create a Clustered Index on VibeFGEvents.id after your SELECT INTO the table will be sorted on disk by VibeFGEvents.id.

    0 讨论(0)
提交回复
热议问题