Session
Dynamic Pivot – Making Columns out of Rows
You have a result set in relational format, but you want to pivot the result set for presentational reasons, so that that the values in some column(s) in the result set become columns in what the user sees. Very often, you don’t know these values beforehand, so the pivot operation needs to be dynamic.
To be able to write a dynamic pivot, you need two master two things: writing static pivot queries and dynamic SQL.
In this session, we will start learning how to write static pivot queries. In case you already feel acquainted with the PIVOT operation in T-SQL, here is a teaser: we will not use that operator, but a much more flexible scheme.
Next, we will move on to the basics of dynamic SQL. Dynamic SQL itself is quite an advanced feature, but we will only have time for the basics – and some words of caution.
Finally, we will put these things together and learn how to write dynamic pivots. We will look at one example in detail, but the download material come with a few more examples to study on your own.
This is a level-200 session. Preferably, you should have been working with writing queries and stored procedures for two-three years to have full benefit of the session.
Erland Sommarskog
Erland Sommarskog SQL-Konsult AB
Stockholm, Sweden
Links
Please note that Sessionize is not responsible for the accuracy or validity of the data provided by speakers. If you suspect this profile to be fake or spam, please let us know.
Jump to top