Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Merging and Regrouping Dates From Multiple Tables

Author  Topic 

leighmo83
Starting Member

1 Post

Posted - 2014-08-19 : 16:24:58
I have three tables: one for each type of service. Each table lists a client's price for that particular service for different date periods:


TABLE: SERVICE_A
| StartDate | EndDate | Price |
----------------------------------------
| 01/01/2013 | 16/04/2013 | 30 |
| 17/04/2013 | 20/09/2013 | 33 |
| 21/09/2013 | 31/12/2013 | 34 |


TABLE: SERVICE_B
| StartDate | EndDate | Price |
----------------------------------------
| 01/01/2013 | 30/06/2013 | 47 |
| 01/07/2013 | 31/12/2013 | 49 |


TABLE: SERVICE_C
| StartDate | EndDate | Price |
----------------------------------------
| 01/01/2013 | 03/03/2013 | 96 |
| 04/03/2013 | 31/12/2013 | 101 |



I am trying to create one table that merges this data and restructures it to show the prices of all three services in the appropriate date ranges:


RESULTS
| StartDate | EndDate | PriceA | PriceB | PriceC |
----------------------------------------------------------
| 01/01/2013 | 03/03/2013 | 30 | 47 | 96 |
| 04/03/2013 | 16/04/2013 | 30 | 47 | 101 |
| 17/04/2013 | 30/06/2013 | 33 | 47 | 101 |
| 01/07/2013 | 20/09/2013 | 33 | 49 | 101 |
| 21/09/2013 | 31/12/2013 | 34 | 49 | 101 |



Any help with this query would be very much appreciated!
   

- Advertisement -