Thank you for looking to help. I have a table like this. Lets call it TableA
[Id] [CHAR](10) NOT NULL,
[DType] [SMALLINT] NOT NULL,
[PType] [CHAR](1) NOT NULL,
[Period] [INT] NOT NULL,
[FromDate] [SMALLDATETIME] NOT NULL,
[ToDate] [SMALLDATETIME] NOT NULL,
[Highval] [DECIMAL](19, 4) NULL,
The Primary Key is Id, DType, PType, Period, FromDate
There is data in it like this:
Id DType PType Period FromDate ToDate Highval
-------------------------------------------------------------------
000000000G 1 A 2015 2014-11-02 2014-11-04 0.4800
000000000G 1 A 2015 2014-11-01 2014-11-01 1.2860
000000000G 1 A 2015 2014-10-28 2014-10-31 1.2290
000000000K 4 2 2015 2014-12-17 2014-12-20 2.5800
000000000K 4 3 2015 2014-12-15 2014-12-16 2.1700
000000000K 4 3 2015 2014-11-14 2014-12-14 2.7200
I need a way to split the date ranges, anything greater than or equal to FromDate and less than or equal to ToDate, I need to split them into another column called IndividualDate
into the same table. Basically, in the given date ranges, if the date exists between the FromDate
and ToDate
write the date in another column called IndividualDate
. For a given Id
, DType
, PType
, PEnd
, FromDate
, the FromDate
and ToDate
field date ranges do not have duplicates. So, the date ranges are cleanly separated. The final output table(temporary table is fine) for the above sample data would look like this.
Id DType PType Period FromDate ToDate Highval IndividualDate
----------------------------------------------------------------------------------
000000000G 1 A 2015 2014-11-02 2014-11-04 0.4800 2014-11-02
000000000G 1 A 2015 2014-11-02 2014-11-04 0.4800 2014-11-03
000000000G 1 A 2015 2014-11-02 2014-11-04 0.4800 2014-11-04
000000000G 1 A 2015 2014-11-01 2014-11-01 1.2860 2014-11-01
000000000G 1 A 2015 2014-10-28 2014-10-31 1.2290 2014-10-28
000000000G 1 A 2015 2014-10-28 2014-10-31 1.2290 2014-10-29
000000000G 1 A 2015 2014-10-28 2014-10-31 1.2290 2014-10-30
000000000G 1 A 2015 2014-10-28 2014-10-31 1.2290 2014-10-31
000000000K 4 2 2015 2014-12-17 2014-12-20 2.5800 2014-12-17
000000000K 4 2 2015 2014-12-17 2014-12-20 2.5800 2014-12-18
000000000K 4 2 2015 2014-12-17 2014-12-20 2.5800 2014-12-19
000000000K 4 2 2015 2014-12-17 2014-12-20 2.5800 2014-12-20
000000000K 4 3 2015 2014-12-15 2014-12-16 2.1700 2014-12-15
000000000K 4 3 2015 2014-12-15 2014-12-16 2.1700 2014-12-16
000000000K 4 3 2015 2014-11-14 2014-12-14 2.7200 2014-12-14
Any suggestions would be greatly appreciated. Thank you in advance.