Hello Forum Members,
CREATE TABLE #Temp_Actual(
[City] [nvarchar](255) NULL,
[Sales] float Null,
[Act_Date] [datetime] NULL
)
Insert into #Temp_Actual values ('Seattle',12,'12-January-2014')
Insert into #Temp_Actual values ('Seattle',10,'15-June-2014')
Insert into #Temp_Actual values ('Austin',20,'22-June-2014')
CREATE TABLE #Temp_Demand(
[City] [nvarchar](255) NULL,
[Demand] float Null,
[Demand_Date] [datetime] NULL
)
Insert into #Temp_Demand values ('Seattle',25,'12-July-2014')
Insert into #Temp_Demand values ('Seattle',30,'13-July-2014')
Insert into #Temp_Demand values ('Austin',40,'15-August-2014')
CREATE TABLE #Temp_Supply(
[City] [nvarchar](255) NULL,
[Supply] float Null,
[Supply_Date] [datetime] NULL
)
Insert into #Temp_Supply values ('Seattle',40,'15-July-2014')
Insert into #Temp_Supply values ('Seattle',50,'15-October-2014')
Insert into #Temp_Supply values ('Austin',60,'15-August-2014')
View Output:
City | Demand | Cumilative Demand | Actual | Cumilative Actual | Supply | Cumilative Supply | Trend | Date | ||||
Seattle | 0 | 0 | 22 | 22 | 0 | 0 | -22 | January,2014 | (cumilative supply - cumilative Actual) | |||
Seattle | 10 | 10 | 0 | 32 | 0 | 0 | -32 | June,2014 | (cumilative supply - cumilative Actual) | |||
Seattle | 55 | 65 | 0 | 32 | 40 | 40 | -15 | July,2014 | (cumilative supply - cumilative demand) | |||
Seattle | 0 | 65 | 0 | 32 | 50 | 90 | 25 | October,2014 | (cumilative supply - cumilative demand) | |||
Austin | 0 | 0 | 20 | 20 | 0 | 0 | -20 | June,2014 | (cumilative supply - cumilative Actual) | |||
Austin | 40 | 40 | 0 | 20 | 60 | 60 | 20 | Aug,2014 | (cumilative supply - cumilative demand) |
Trend Formula:
Future Dates | (cumilative supply - cumilative demand) | ||
Past Dates | (cumilative supply - cumilative Actual) |
Best Regards,
Sqlquery9