SELECT INTO a table variable in T-SQL

前端 未结 8 1851
你的背包
你的背包 2020-11-30 16:55

Got a complex SELECT query, from which I would like to insert all rows into a table variable, but T-SQL doesn\'t allow it.

Along the same lines, you c

相关标签:
8条回答
  • 2020-11-30 17:54

    Try something like this:

    DECLARE @userData TABLE(
        name varchar(30) NOT NULL,
        oldlocation varchar(30) NOT NULL
    );
    
    INSERT INTO @userData (name, oldlocation)
    SELECT name, location FROM myTable
    INNER JOIN otherTable ON ...
    WHERE age > 30;
    
    0 讨论(0)
  • 2020-11-30 17:55

    Try to use INSERT instead of SELECT INTO:

    INSERT @UserData   
    SELECT name, location etc.
    
    0 讨论(0)
提交回复
热议问题