【问题标题】:Trying to insert a stored procedure into a temporary table, getting 'an object or column name is missing or empty' [duplicate]尝试将存储过程插入临时表,得到“对象或列名丢失或为空”[重复]
【发布时间】:2012-04-26 02:45:35
【问题描述】:

可能重复: How to SELECT * INTO [temp table] FROM [Stored Procedure]

我是T-SQL 的新手。我有一个选择记录的stored procedure。我想查询存储过程返回的记录,所以我试图将记录插入到临时表中。 (堆栈溢出帖子和其他帖子说这是怎么做的。)

但是当我尝试时,我得到了错误:

对象或列名丢失或为空'

当我刚刚运行存储过程时,我得到了一个包含名称列的表。

select * into #temp1
exec alexander.dbo.get_uberrecords '20120101', '20120201', 'labcorp' //throws error saying columns must have names

但是

exec alexander.dbo.get_uberrecords '20120101', '20120201', 'labcorp' // Returns cols with names

我错过了什么?

【问题讨论】:

    标签: sql-server tsql


    【解决方案1】:

    先尝试创建临时表:

    CREATE TABLE #temp1
    (
       COL1 INT,
       COL2 VARCHAR(MAX)   
    )
    
    INSERT INTO #temp1 
    exec alexander.dbo.get_uberrecords '20120101', '20120201', 'labcorp'
    

    如果您的结果集非常广泛,您可能希望使用OPENROWSET

    无论如何,这个 SO 有很多选择: Insert results of a stored procedure into a temporary table

    【讨论】:

    • @Jeff--不幸的是它是一个巨大的 40 列表,所以这不是一个很好的选择
    猜你喜欢
    • 1970-01-01
    • 2021-12-12
    • 1970-01-01
    • 1970-01-01
    • 2019-01-09
    • 2020-01-26
    • 2018-11-16
    • 2022-01-24
    相关资源
    最近更新 更多