Linked Questions

Popular Questions

Complex pivot query in SQL Server

Asked by At

I have a table that looks like this in SQL Server:

Status 1233SDD 1234SDD 1235SDD
Description Points Points Points
Source Website Website Website
Frequency 15 days 15 days 10 days
Country Australia Canada Albania
January2021 80 80 50
February2021 80 60 50
March2021 80 40 50
April2021 20 40 50
June2021 10 40 50

I pivot it and get a result that will look similar to this:

Status Description Source Frequency Country Month/Year Points
1233SDD Points Website 15 days Australia January2021 80
1233SDD Points Website 15 days Australia February2021 80
1233SDD Points Website 15 days Australia March2021 80
1233SDD Points Website 15 days Australia April2021 20
1233SDD Points Website 15 days Australia June2021 10
1234SDD Points Website 15 days Canada January2021 80
1234SDD Points Website 15 days Canada February2021 60

I don't even know where to start considering the data it's all over the place, any ideas?

Edit: The months cannot be a column because the table will be updated with new rows frequently, sometimes with two different types of data for the same month. The month column dates also back from year 2012 to current year 2022, so that's why it cannot be a column in itself.

The data comes in files as the table 1 and needs to be transformed as table 2 in SQL.

Related Questions