SQL run from Excel cannot use a temporary table

后端 未结 2 1113
执念已碎
执念已碎 2020-12-25 13:25

I have been able to create a data connection from Excel to SQL Server and execute many SQL queries successfully. But I cannot get any TSQL to work if it includes a temporary

相关标签:
2条回答
  • 2020-12-25 14:18

    I wanted to add to the above answer - just using SET NOCOUNT ON at the top of the query, with a regular temp table SELECT name INTO #Names FROM Employee should work.

    A table variable is not needed here.

    You could also add SET ANSI_WARNINGS OFF to avoid messages like "NULL Value is eliminated by an aggregate".

    0 讨论(0)
  • 2020-12-25 14:24

    The following appears to work ...

    set nocount on
    declare @t table(fid int)  -- I'm sure I could add the rest of the columns if I wanted to
    insert @t select freq_id from compass3.dbo.freq
    select * from @t where fid>2
    

    So as long as I turn nocount on and use a table variable rather than a temporary table, I can achieve what I need.

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