budi
Starting Member
5 Posts |
Posted - 2010-08-19 : 05:13:22
|
Dear All,Let’s say I have a table as below :CREATE TABLE schedule (PlantNo CHAR (10),CompCode VARCHAR (20), Budget MONEY,Qty INT, NextDue1 DATETIME,NextDue2 DATETIME,NextDue3 DATETIME)INSERT INTO schedule VALUES('DR501','1000-1','9500','1','7/8/2010','9/12/2010','11/25/2010')INSERT INTO schedule VALUES('DR502','1000-2','9000','2','9/8/2010','11/11/2010',NULL)INSERT INTO schedule VALUES('DR503','1000-3','8500','1','9/29/2010',NULL,NULL)INSERT INTO schedule VALUES('DR504','1000-3','8500','3','10/10/2010','12/6/2010',NULL)I want to create pivot as below, with dynamic monthly column base on all due date occurred in the table, the budget value will fill in each month column, so I can get the total budget for each month.Expected tablePlantNo CompCode Budget Qty NextDue1 Jul-10 Aug-10 Sep-10 Oct-10 Nov-10 Dec-10DR501 1000-1 9500 1 8-Jul-10 9500 NULL 9500 NULL 9500 NULLDR502 1000-2 9000 2 8-Sep-10 NULL NULL 9000 NULL 9000 NULLDR503 1000-3 8500 1 29-Sep-10 NULL NULL 8500 NULL 8500 NULLDR504 1000-3 8500 3 10-Oct-10 NULL NULL NULL 8500 NULL 8500Please advise how I can make this happen, thanks in advance.Salam,Budi |
|