TSQL select into Temp table from dynamic sql

前端 未结 5 1207
星月不相逢
星月不相逢 2020-12-03 13:35

This seems relatively simple, but apparently it\'s not.

I need to create a temp table based on an existing table via the select into syntax:

SELECT *         


        
5条回答
  •  借酒劲吻你
    2020-12-03 14:13

    DECLARE @count_ser_temp int;
    DECLARE @TableName AS VARCHAR(100)
    SELECT @TableName = 'TableTemporal'
    
    EXECUTE ('CREATE VIEW vTemp AS
        SELECT *
        FROM ' + @TableTemporal)
    SELECT TOP 1 * INTO #servicios_temp  FROM vTemp
    
    DROP VIEW vTemp
    
    -- Contar la cantidad de registros de la tabla temporal
    SELECT @count_ser_temp = COUNT(*) FROM #servicios_temp;
    
    -- Recorro los registros de la tabla temporal 
    WHILE @count_ser_temp > 0
     BEGIN
     END
    END
    

提交回复
热议问题