How to Pivot Your Data in T-SQL for SQL Server - Static and Dynamic Column Examples

preview_player
Показать описание
In this episode, we're going to look at how to pivot your data in SQL Server T-SQL queries. Pivoting is a very useful way of transforming data, and one of the most effective ways to show summary data. First I'll show you how to do a pivot query with static columns, and then I'll show you a more advanced method that will allow you to have a dynamic display of an unknown number of columns. This tutorial will also introduce you to the STRING_AGG function, which simplifies the creation of a delimited list in SQL Server 2017+ and Azure SQL environments.

For developers looking for a new role, check out and sign up:

Needing to hire technical resources for your project? Get the best:

Want to get access to premium content made just for you and have a chat with me? Find me on Patreon :

Demo of my BZ RDP Cloaker:

Want to work with me 1:1? Contact me today and book your free 20 min consultation!

Follow me on social media:

Get Microsoft Office including Access:

Got a YouTube Channel? I use TubeBuddy, it is awesome. Give it a try:

#sqlserver #pivot #tsql

Рекомендации по теме
Комментарии
Автор

Thank you so much, first video that helped me solve my problem with pivoting :)

joannanowacka
Автор

Such a great video Sean! I have saved this in my SQL favs to reference as and when needed! This actually solves an issue I have now. I have followed along and so far so good. I am at the point where i need to creat my own version of the @myquery string. One question are you using the + as a line break as you would when line breaking a string in VBA? Thx again Sean.

dads_random_projects
Автор

Hi, I have a question, the data which is generated using aggregation in pivot, can we modify the data into another format. for example, if we have 0's and 1's in the data i need to replace them with desired format like 0 to NO, 1 to Yes . Can you please help

mittapalliniveditha
visit shbcf.ru