pivot not working in SSIS

2019-09-08 17:12发布

问题:

My SQL query works fine when i execute it in SQL management studio but throw the error below when execute in SSIS package. Any advise?

**When click on Build Query of the syntax - it shows

The PIVOT SQL construct or statement is not supported.
Case 1:

SELECT listid, 
               [1] 
        FROM   (SELECT listid, 
                       val, 
                       [order] 
                FROM   gmt_listsvals) P 
               PIVOT (Max (val) 
                     FOR [order] IN ([1])) AS pvt

Case 2:

SELECT comb_id, [orgunit], [time], [gender], [jobcategory], [ethnicity], [gradegroup], [regiongeo], [emplclass], operatorid,  seq_id,  sequance_name, listid 
FROM   (SELECT C.comb_id, dim_name, V.operatorid,V.seq_id, V.listid, dim_value, S.sequance_name 
        FROM   gmt_combinationsflat C 
            JOIN gmt_valuesflat V ON C.comb_id = V.comb_id 
            JOIN gmt_rangeseq S ON V.seq_id = S.seq_id 
            JOIN gmt_dimensions D ON C.dim_id = D.dim_id 
        WHERE  C.kpi_id = 9 AND C.last = 1) P 
PIVOT (Max(dim_value) FOR dim_name IN ( [ORGUNIT ], [Time ], [Gender ], [JobCategory ], [Ethnicity ], [GradeGroup ],  [RegionGeo ], [EmplClass ] ) ) AS pvtt

Error

Exception from HRESULT: 0xC0202009 Error at ..: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E21. An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80040E21 Description: "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.".

回答1:

That statement is equivalent to:

select listid, max(case when [order] = 1 then val end) as [1]
from gmt_listsvals
group by listid