在查询结果中显示重复的列值,除了t-sql中的第一行之外。

时间:2021-08-20 08:00:45

I edited my question:

我编辑的问题:

I get an Invalid object name '#Temp1'. The code below runs in a cursor loop...

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

Code:

代码:

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

1 个解决方案

#1


2  

Remove the 't' from:

删除“t”:

Into #Temp  t

So:

所以:

INTO #Temp 

An alias is not allowed with INTO

不允许使用别名。

I'd also recommend abandoning deprecated implicit joins:

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

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  

#1


2  

Remove the 't' from:

删除“t”:

Into #Temp  t

So:

所以:

INTO #Temp 

An alias is not allowed with INTO

不允许使用别名。

I'd also recommend abandoning deprecated implicit joins:

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

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