June 10, 2011 at 4:16 pm
I made a small syntax error in this query, and would have expected an error when I tried to run it. The results are quite interesting.
SELECT ExtraValue,VendorID
Employee, Orders
FROM
(SELECT 'extra value' as ExtraValue, 1 as VendorID, 'e1' as Emp1, 'e2' as Emp2, 'e3' as Emp3, 'e4' as Emp4, 'e5' as Emp5
) p
UNPIVOT
(Orders FOR Employee IN
(Emp1, Emp2, Emp3, Emp4, Emp5)
) AS unpvt
June 10, 2011 at 10:19 pm
flyingrockfishguy (6/10/2011)
I made a small syntax error in this query, and would have expected an error when I tried to run it. The results are quite interesting.SELECT ExtraValue,VendorID
Employee, Orders
FROM
(SELECT 'extra value' as ExtraValue, 1 as VendorID, 'e1' as Emp1, 'e2' as Emp2, 'e3' as Emp3, 'e4' as Emp4, 'e5' as Emp5
) p
UNPIVOT
(Orders FOR Employee IN
(Emp1, Emp2, Emp3, Emp4, Emp5)
) AS unpvt
Any chance of you telling us what the syntax error you made is so we don't have to look for it? 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
June 11, 2011 at 1:22 am
flyingrockfishguy (6/10/2011)
I made a small syntax error in this query, and would have expected an error when I tried to run it. The results are quite interesting.SELECT ExtraValue,VendorID
Employee, Orders
FROM
(SELECT 'extra value' as ExtraValue, 1 as VendorID, 'e1' as Emp1, 'e2' as Emp2, 'e3' as Emp3, 'e4' as Emp4, 'e5' as Emp5
) p
UNPIVOT
(Orders FOR Employee IN
(Emp1, Emp2, Emp3, Emp4, Emp5)
) AS unpvt
Do you mean the missing comma at the end of the first line? You ended up aliasing the "VendorID" column as Employee (remember that the AS keyword is optional). There wasn't a syntax error with that, so SQL just went and did what you told it to.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply