0

我编辑了我的问题:

我得到一个无效的对象名称“#Temp1”。下面的代码在游标循环中运行...

代码:

IF OBJECT_ID('tempdb..#Temp1') IS NOT NULL
                BEGIN
                    DROP TABLE #Temp1
                END

                    Insert Into #Temp1 
                    Select o.EventSetName,
                           o.EventSetDisplay,
                           o.EventSetDescription,
                           o.ChildSetName,
                           ROW_NUMBER() Over (Order By o.ChildSetName) RN                  
                    From   ##ObsSetLevel o,
                           ##Final f
                    Where  f.ChildSetName = o.EventSetName and 
                           o.EventSetName = @ObsSetList 
                    Order By o.ChildSetName asc  

                    Insert into ##Final
                    Select *
                    From #Temp1
                    Where  RN = 1
                    Union
                    Select '', '', '', ChildSetName, RN
                    From #Temp1
                    Where RN > 1
4

1 回答 1

2

从以下位置删除“t”:

Into #Temp  t

所以:

INTO #Temp 

不允许使用别名INTO

我还建议放弃已弃用的隐式连接:

SELECT  o.EventSetName,
        o.EventSetDisplay,
        o.EventSetDescription,
        o.ChildSetName,
        ROW_NUMBER() Over (Order By o.ChildSetName) RN
INTO #Temp 
FROM    ##ObsSetLevel o
JOIN    ##Final f
    ON  f.ChildSetName = o.EventSetName 
        AND o.EventSetName = @ObsSetList 
ORDER By o.ChildSetName asc  
于 2013-08-15T19:03:53.300 回答