HOME > Office programs > Pivot T-Sql: How To Use

Pivot T-SQL: How to use

Microsoft offers the Transact-SQL reference, a database engine that gives you all the tools and applications you need to communicate with an SQL database. This includes various operators such as PIVOT and UNPIVOT. However, there are several points to consider here.

How to use PIVOT from T-SQL

There are several tools from Microsoft, such as Azure Data Studio or sqlcmd, that use T-SQL commands. In addition, you have different operators available. For example, the relational operators PIVOT and UNPIVOT can be used to modify a table value expression within another table. In the output, the unique values of a column are split into several columns. However, there are a few points to keep in mind when using them.
  1. If you want a detailed description of the syntax of the PIVOT operator, it is worth looking at Microsoft's documentation. There, numerous examples are given on how to use the operator.
  2. The syntax basically consists of a SELECT command with: SELECT<non-pivot column >, [first pivot column] AS <column name>. This is followed by a FROM (<SELECT query that generates the data>) AS <alias for the source query>.
  3. Followed by the PIVOT operator. This is generally structured as follows: PIVOT (<aggregation function>(<column that will be aggregated>) FOR [<column that contains the values that will become the column header>] IN ( [first pivot column] ... [last pivot column])) AS <Alias for the pivot table>.
  4. Replace the appropriate placeholders such as "last pivot column" with the appropriate labels.
  5. With this query, it is then possible to create a pivot table also in Excel with the data from the database.

By Hernando Bucke

Spotify sleep mode - how to turn it on :: iPhone X: Remove sim lock - how to do it
USEFUL LINKS