Skip to content
Advertisement

Creating a Pivot Table in SQL

I could use some help with creating a PIVOT table.

The table that I’m looking to pivot from is:

Where I want to change it into the Format of

Which has the tracking number as the Row Identifier, the added columns are the Unique Values in the ‘Surcharge Reason’ column, and the values of the data are the Surcharge Amount if there is any for that Track Number & Surcharge Reason

Any help on sending me down the right path would be very much appreciated.

Advertisement

Answer

You can achieve your expected output using case statement. here is an example.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement