1

Did I stumble across a reserved word here or something?

For, the following statement:

SELECT [Type] 
FROM (SELECT 'Receive' AS [Rec], 'Transfer' AS [Trx]) [data]
UNPIVOT
(
    [Orders] FOR [Type] IN ([Rec], [Trx])
) AS [unpvt];

produces this exception/error: The type of column "Trx" conflicts with the type of other columns specified in the UNPIVOT list.


Working Sample

SELECT [Type]    
FROM 
--(SELECT 'Receive' AS [Rec], 'Transfer' AS [Trx]) [data]
(SELECT 'Rec_eive' AS [Rec], 'Transfer' AS [Trx]) [data]
UNPIVOT
(
    [Orders] FOR [Type] IN ([Rec], [Trx])
) AS [unpvt];

Database Explorer: data.stackexchange.com | Simple Unpivot - Column Conflict


Hannah Vernon
  • 70,928
  • 22
  • 177
  • 323

0 Answers0