I have following two source and one destination tables in sql server 2008R2. How can I do pivot(s) in TSQL to get to the destination from sources? I need it urgently.
Source Table 1: ProdType
key name
--------------
1 Magazines
2 Journals
3 Books
4 Newspaper
Source Table 2: Orders
seqno ODate Key Qty UnitPrice
--------------------------------------------------
1 2013-10-12 1 10 5
2 2013-10-12 4 20 3
3 2013-10-13 2 5 3
4 2013-10-14 4 50 5
5 2013-10-15 1 100 2.5
Destination Table: Orders Detail
Odate Magazine Journals Books Newspaper
-----------------------------------------------------------------
12/10/2013 10 5 0 0 0 0 20 3
13/10/2013 0 0 5 3 0 0 0 0
14/10/2013 0 0 0 0 0 0 50 5
15/10/2013 100 2.5 0 0 0 0 0 0
-----------------------------------------------------------------
NOTE *qty *unit price
Any help would be greatly appreciated! As you can tell, I'm quite new to T-SQL (or SQL in general) and SQL Server. Thanks in advance!