In the last example, we grouped the data by the first four columns.
As you can see, you can set filtering, visibility of certain data, and other parameters in the context menu.
Now, let’s get back to pivoting our table. Click Pivot Table and select the necessary fields:
You need to select a column in the top right and the necessary command in the bottom right:
- Row Area – to a row
- Column Area – to a table
- Filter Area – to a filter
- Data Area – to data
- And then press Add To.
In our example, the
Row Area command was selected for the following attributes:
- EmployeeID
- LastName
- FirstName
- SkillName
The
Column Area command was selected for the Year column.
The Data Area command was selected for the PeriodDay attribute.
Creating a user report in dbForge Studio for SQL Server
Let’s now briefly discuss creating user reports in dbForge Studio for SQL Server.
First, go to Database\Report Designer:
Fig.11 Navigating to the user report functionality
In the window that will be opened, select the desired report type (in this case, it’s Standard Report) and click Next:
Now, select the connection and data type (in this case, Custom Query) and then click Next,
Fig.13 Configuring the report’s connection
Keep in mind that you can select the Simple Table/View data type instead of Custom Query if you need to build the report from one table or view. In this particular case, we need to select Custom Query as the report is built on the data from several tables.
You should also remember that the connection to a specific database should be established with SQL Server authentication, otherwise the query won’t work.
Let’s insert the necessary query and click Next:
Fig.14 User query for the report
If you click Design before clicking Next, Query Builder will be opened. With its help, you can visually create the query you need.
The Load button allows you to load a previously saved query script.
Next, choose all the columns needed for the report and press Next,
Fig.15 Selecting the fields on which you need to report
Then, configure the grouping and click Next:
Fig.16 Configuring grouping for the report
Next, select the necessary aggregate functions and ignore the NULL-values as we don’t need them for data analysis,
Fig.17 Setting data aggregation for the report
Here, we’ll leave default settings and only change the page orientation from portrait to landscape,
Fig.18 Configuring the report page
We’ll leave the Bold style and click Next,
Fig.19 Configuring the report style
Finally, let’s name the report and click Finish,
Fig.20 Specifying the report’s name
You can always return to any of the previous steps by clicking Back and save the report as a .bat file with the help of the Save Command Line button or even cancel the report creation by clicking Cancel.
Here’s the resulting report project,
Fig.21 New user report
Report results can be saved in various frequently-used formats like RDP, HTML, RTF, and others.
The report projects are saved in the RDB format and you can edit them as easily with dbForge Studio for SQL Server as you can RDL files in the
Report Builder or in
Visual Studio.
Conclusion
When there is a need to change how data is displayed in a database, we often need to transpose data from rows to columns, that is, to pivot tables. In this article, we provided a step-by-step guide on how to perform the PIVOT command in a T-SQL script and with dbForge Studio for SQL Server. The latter tool enables to set filtering as well as visibility of certain data and allows users to save reports in different widely-used formats including RDP, HTML, RTF, which makes it easier for users to edit.