INSERT INTO @TABLE EXEC @query with SQL Server 2000

前端 未结 3 1552
不知归路
不知归路 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:34

    DECLARE @q nvarchar(4000)
    SET @q = 'DECLARE @tmp TABLE (code VARCHAR(50), mount MONEY)
    INSERT INTO @tmp
      (
        code,
        mount
      )
    SELECT coa_code,
           amount
    FROM   T_Ledger_detail
    
    SELECT *
    FROM   @tmp'
    
    EXEC sp_executesql @q
    

    If you want in dynamic query

提交回复
热议问题