I was wondering if you can do the following with SQL. Suppose you have a table like this:
r| Company | SoldToCustomer | Amount | Date
1| A | A1 | 100 | 27-12-1989
2| A | A2 | 200 | 20-02-1990
3| A | A1 | 500 | 20-03-1991
4| A | A2 | 800 | 30-01-1992
5| B | A1 | 900 | 31-01-1992
6| B | A2 | 1000 | 01-02-1993
...
Notice: that the r is just an indicator and not part of the table. It indicates the row number. I would like to transform it into a table like the following:
r| Company | AmountToCompanyA1 | AmountToCompanyA2 | Date
1| A | 100 | . | 27-12-1989
2| A | . | 200 | 20-02-1990
3| A | 500 | . | 20-03-1991
4| A | . | 800 | 30-01-1992
5| B | 900 | . | 31-01-1992
...
Where . indicates a missing value. I am well aware that this kind of storage is redundantly and it is giving me a very big table, but I was wondering whether this kind of transformation is possible in SQL.
Please be aware that even though I have only used two A1 and A2, there are about 9000 A's, so this is impossible to do by hand.
I actually only wanted to create a SQL view of this.
PS: I am trying to do this in Microsoft SQL Server Management Studio.
Thanks!