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
CONVERT(varchar(16), 'Receive') [Rec]doesn't resolve the issue... – Brett Caswell Jul 24 '15 at 21:15SELECT [Type] FROM (SELECT cast('Receive' as varchar(8)) AS [Rec], 'Transfer' AS [Trx]) [data] UNPIVOT ( [Orders] FOR [Type] IN ([Rec], [Trx]) ) AS [unpvt];works ! I marked this a dupe because your resolution is exactly the same - datatype length should be same - not more or less. – Kin Shah Jul 24 '15 at 21:27SELECT [Type] FROM (SELECT CONVERT(VARCHAR(32),'Receive') AS [Rec], CONVERT(VARCHAR(32),'Transfer') AS [Trx]) [data] UNPIVOT ( [Orders] FOR [Type] IN ([Rec], [Trx]) ) AS [unpvt];, why are you so insistent that this isn't a datatype/length issue at all? I can assure you it's not a reserved word problem, and I can also assure you you're not going to get a more detailed answer here than what Paul already provided on the original question. This absolutely fits the textbook definition of a duplicate, sorry. – Aaron Bertrand Jul 24 '15 at 21:42