Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
A little SQL quiz
Message
From
29/06/2014 14:37:42
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Application:
Web
Miscellaneous
Thread ID:
01602842
Message ID:
01602848
Views:
62
>
>SELECT SalesManID, xmonth, V
>  FROM dbo.SalesTemp  AA
>   UNPIVOT (V FOR XMONTH IN (Jan, Feb, Mar)
>           ) XDATA
>
Exactly, thanks very much.

The UNPIVOT (as well as the CROSS APPLY) will usually generate execution plans that are much better than the "older" approach

I inherited some code last year with a table that had several million rows and about 50 columns, and it initially used the "older" approach. It took minutes to run. Changed it to use UNPIVOT and it ran in seconds.
Previous
Reply
Map
View

Click here to load this message in the networking platform