Sql server 枢轴功能长时间运行

Sql server 枢轴功能长时间运行,sql-server,tsql,Sql Server,Tsql,查询长时间运行而不产生任何结果。上述代码是否有遗漏?请告知 IF OBJECT_ID('tempdb..#temp1') IS NOT NULL DROP TABLE #temp1 GO CREATE TABLE #TEMP1 ( CounterSeq nvarchar(200),COUNTER INT ) INSERT INTO #TEMP1 VALUES ('Counter1','1') INSERT INTO #TEMP

查询长时间运行而不产生任何结果。上述代码是否有遗漏?请告知

IF OBJECT_ID('tempdb..#temp1') IS NOT NULL DROP TABLE #temp1
    GO

    CREATE TABLE #TEMP1 
    (
      CounterSeq nvarchar(200),COUNTER INT   
    )
    INSERT INTO #TEMP1 VALUES ('Counter1','1')
    INSERT INTO #TEMP1 VALUES ('Counter2','2')
    INSERT INTO #TEMP1 VALUES ('Counter3','3')
    INSERT INTO #TEMP1 VALUES ('Counter4','4')
    INSERT INTO #TEMP1 VALUES ('Counter5','5')
    INSERT INTO #TEMP1 VALUES ('Counter6','6')
    INSERT INTO #TEMP1 VALUES ('Counter7','7')
    INSERT INTO #TEMP1 VALUES ('Counter8','8')
    INSERT INTO #TEMP1 VALUES ('Counter9','9')
    INSERT INTO #TEMP1 VALUES ('Counter10','10')
    INSERT INTO #TEMP1 VALUES ('Counter11','11')
    INSERT INTO #TEMP1 VALUES ('Counter12','12')
    INSERT INTO #TEMP1 VALUES ('Counter13','13')
    INSERT INTO #TEMP1 VALUES ('Counter14','14')



    SELECT Counter1,Counter2,Counter3,Counter4,Counter5,Counter6,Counter7,Counter8,Counter9,Counter10 from  
    (select B.METER_VALUE As VALUE,A.SEQ AS SEQUENCE,T.COUNTER AS COUNTER
                    from tblCOUNTER B inner join tblSEQUENCE A On B.seq=A.SEQ INNER JOIN #TEMP1 T
                     ON A.SEQ=T.SEQUENCE)
                             x
            pivot 
            (
                max(VALUE)
                for COUNTER in (Counter1,Counter2,Counter3,Counter4,Counter5,Counter6,Counter7,Counter8,Counter9,Counter10)
            ) p 

等待统计信息说什么?
select*from sys.dm_exec_requests where session_id=yoursessionid
wait统计信息说什么?
select*from sys.dm_exec_requests where session_id=yoursessionid
---I created table and data in temporary tables, verify whether you want something likke that or not?
IF OBJECT_ID('tempdb..#temp1') IS NOT NULL DROP TABLE #temp1
GO
CREATE TABLE #TEMP1 
(
  COUNTER nvarchar(200),SEQUENCE INT   
)
INSERT INTO #TEMP1 VALUES ('Counter1','1')
INSERT INTO #TEMP1 VALUES ('Counter2','2')
INSERT INTO #TEMP1 VALUES ('Counter3','3')
INSERT INTO #TEMP1 VALUES ('Counter4','4')
INSERT INTO #TEMP1 VALUES ('Counter5','5')
INSERT INTO #TEMP1 VALUES ('Counter6','6')
INSERT INTO #TEMP1 VALUES ('Counter7','7')
INSERT INTO #TEMP1 VALUES ('Counter8','8')
INSERT INTO #TEMP1 VALUES ('Counter9','9')
INSERT INTO #TEMP1 VALUES ('Counter10','10')

IF OBJECT_ID('tempdb..#tblCOUNTER') IS NOT NULL DROP TABLE #tblCOUNTER
GO

Create table #tblCOUNTER
(
    seq int,METER_VALUE int
)
Insert into #tblCOUNTER Values(2,15006)
Insert into #tblCOUNTER Values(3,178383)
Insert into #tblCOUNTER Values(8,0)
Insert into #tblCOUNTER Values(1,29641)
Insert into #tblCOUNTER Values(1,77422)
Insert into #tblCOUNTER Values(10,1663)


select Counter1,Counter2,Counter3,Counter4,Counter5,Counter6,Counter7,Counter8,Counter9,Counter10
from
(
    select Meter_Value, Counter
    from 
        (
            Select A.COUNTER,Max(B.METER_VALUE) as Meter_Value --into #Temp2
            From #TEMP1 as A Left Join #tblCOUNTER as B
            On A.SEQUENCE=B.seq
            Group by A.COUNTER      
        )as Qry
) d
pivot
(
    max(Meter_Value)
    for Counter in (Counter1,Counter2,Counter3,Counter4,Counter5,Counter6,Counter7,Counter8,Counter9,Counter10)
) piv;