Pivot – Rows into columns in SQL Server using R

We have been using different methods in SQL to convert row data into columns. Some time it’s just the requirement for data visualisation only. To fulfil this requirement mostly we use PIVOT, which is complex and lengthy. In this blog post we will see how can we leverage R in SQL to get our required output?

In case you are new to R, it is a very powerful and popular statistical programming language widely used by data scientist for data analytics. Microsoft has integrated R with SQL Server 2016, it means we can execute R scripts via a system-stored procedure using T-SQL. Query data, pass it to R, and get the results back into SQL Server. Isn’t that amazing?

Note: You need to have R on the server where your SQL instance is installed. Getting started with R



Prasad Sahoo

Prasad Sahoo, is an enthusiast of Microsoft technologies in general and a passionate database professional, mainly focusing on SQL Server performance tuning and business intelligence. He has contributed a long time of his career working on SQL Server and other RDBMS. If he is not busy with SQL stuff then he must be watching some Hollywood movies.

Leave a Reply

%d bloggers like this: