INSERT INTO @TABLE EXEC @query with SQL Server 2000

前端 未结 3 1551
不知归路
不知归路 2020-11-29 01:47

Is it true that SQL Server 2000, you can not insert into a table variable using exec?

I tried this script and got an error message EXECUTE cannot be used as a

3条回答
  •  臣服心动
    2020-11-29 02:40

    The documentation is misleading.
    I have the following code running in production

    DECLARE @table TABLE (UserID varchar(100))
    DECLARE @sql varchar(1000)
    SET @sql = 'spSelUserIDList'
    /* Will also work
       SET @sql = 'SELECT UserID FROM UserTable'
    */
    
    INSERT INTO @table
    EXEC(@sql)
    
    SELECT * FROM @table
    

提交回复
热议问题