SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Merging and Regrouping Dates From Multiple Tables
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

leighmo83
Starting Member

1 Posts

Posted - 08/19/2014 :  16:24:58  Show Profile  Reply with Quote
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!

Edited by - leighmo83 on 08/19/2014 16:25:33
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000