Get all months in EXPAND ON in Teradata










0














I am trying to rewrite a query that has a product join to expand records across a date period with the EXPAND ON function. Here is how it works currently.



SELECT 
t1.key
,MIN(t1.beg_dt)
,MAX(t1.end_dt)
,dates.end_month_dt
FROM t1
INNER JOIN dates
ON t1.beg_dt < dates.end_month_dt
AND t1.end_dt >= dates.end_month_dt
GROUP BY 1,4;


The dates table is just a list of a bunch of date information. end_month_dt is a column that has every end of month date going back several years. (e.g. 1/31/13, 2/28/31, 3/31/13, etc...)



If a record in t1 has beg_dt = 1/1/13 and end_dt = 8/31/13, then this join will create a record for each month in this interval. Like this:



key beg_dt end_dt end_month_dt
1 1/1/13 8/31/13 1/31/13
1 1/1/13 8/31/13 2/28/13
...
1 1/1/13 8/31/13 8/31/13


This query runs poorly and must be split up into a few parts as it contains much more information from t1 and spans several years. I have found that EXPAND ON can yield a very similar result, but I am having a minor issue getting the last month to be included (or the first month). Here is what I have:



SELECT
t1.key
,t1.beg_dt
,t1.end_dt
,BEGIN(prd) as end_month_dt
FROM t1
EXPAND ON PERIOD(t1.beg_dt, t1.end_dt) AS prd BY ANCHOR MONTH_END;


This yields identical results except that it doesn't include the last row. If I were to use END(prd), it would exclude the first row. The issue seems to be that prd = (1/1/13, 8/31/13) and when expanded returns



prd
(1/31/13, 2/28/13)
(2/28/13, 3/31/13)
...
(7/31/13, 8/31/13)


What I really need is the t1 info for all of the dates on the left hand side of each period (1/31 - 7/31) and then the last date on the right hand side (8/31). Is there another way that I can write the EXPAND ON such that I can get that result?



Edit:
I've found that adjusting the beg_dt and end_dt allows me to get the same results although with more functions than I'd usually like to include. It still seems to run and is still much faster than the original.



SELECT
t1.key
,t1.beg_dt
,t1.end_dt
,BEGIN(prd) as end_month_dt
FROM t1
EXPAND ON PERIOD(
CASE
WHEN beg_dt = Last_Day(beg_dt) THEN beg_dt + 1
ELSE beg_dt
END
,CASE
WHEN end_dt = '9999-12-31' THEN end_dt
ELSE end_dt + 1
END) AS prd BY ANCHOR Month_End









share|improve this question




























    0














    I am trying to rewrite a query that has a product join to expand records across a date period with the EXPAND ON function. Here is how it works currently.



    SELECT 
    t1.key
    ,MIN(t1.beg_dt)
    ,MAX(t1.end_dt)
    ,dates.end_month_dt
    FROM t1
    INNER JOIN dates
    ON t1.beg_dt < dates.end_month_dt
    AND t1.end_dt >= dates.end_month_dt
    GROUP BY 1,4;


    The dates table is just a list of a bunch of date information. end_month_dt is a column that has every end of month date going back several years. (e.g. 1/31/13, 2/28/31, 3/31/13, etc...)



    If a record in t1 has beg_dt = 1/1/13 and end_dt = 8/31/13, then this join will create a record for each month in this interval. Like this:



    key beg_dt end_dt end_month_dt
    1 1/1/13 8/31/13 1/31/13
    1 1/1/13 8/31/13 2/28/13
    ...
    1 1/1/13 8/31/13 8/31/13


    This query runs poorly and must be split up into a few parts as it contains much more information from t1 and spans several years. I have found that EXPAND ON can yield a very similar result, but I am having a minor issue getting the last month to be included (or the first month). Here is what I have:



    SELECT
    t1.key
    ,t1.beg_dt
    ,t1.end_dt
    ,BEGIN(prd) as end_month_dt
    FROM t1
    EXPAND ON PERIOD(t1.beg_dt, t1.end_dt) AS prd BY ANCHOR MONTH_END;


    This yields identical results except that it doesn't include the last row. If I were to use END(prd), it would exclude the first row. The issue seems to be that prd = (1/1/13, 8/31/13) and when expanded returns



    prd
    (1/31/13, 2/28/13)
    (2/28/13, 3/31/13)
    ...
    (7/31/13, 8/31/13)


    What I really need is the t1 info for all of the dates on the left hand side of each period (1/31 - 7/31) and then the last date on the right hand side (8/31). Is there another way that I can write the EXPAND ON such that I can get that result?



    Edit:
    I've found that adjusting the beg_dt and end_dt allows me to get the same results although with more functions than I'd usually like to include. It still seems to run and is still much faster than the original.



    SELECT
    t1.key
    ,t1.beg_dt
    ,t1.end_dt
    ,BEGIN(prd) as end_month_dt
    FROM t1
    EXPAND ON PERIOD(
    CASE
    WHEN beg_dt = Last_Day(beg_dt) THEN beg_dt + 1
    ELSE beg_dt
    END
    ,CASE
    WHEN end_dt = '9999-12-31' THEN end_dt
    ELSE end_dt + 1
    END) AS prd BY ANCHOR Month_End









    share|improve this question


























      0












      0








      0


      1





      I am trying to rewrite a query that has a product join to expand records across a date period with the EXPAND ON function. Here is how it works currently.



      SELECT 
      t1.key
      ,MIN(t1.beg_dt)
      ,MAX(t1.end_dt)
      ,dates.end_month_dt
      FROM t1
      INNER JOIN dates
      ON t1.beg_dt < dates.end_month_dt
      AND t1.end_dt >= dates.end_month_dt
      GROUP BY 1,4;


      The dates table is just a list of a bunch of date information. end_month_dt is a column that has every end of month date going back several years. (e.g. 1/31/13, 2/28/31, 3/31/13, etc...)



      If a record in t1 has beg_dt = 1/1/13 and end_dt = 8/31/13, then this join will create a record for each month in this interval. Like this:



      key beg_dt end_dt end_month_dt
      1 1/1/13 8/31/13 1/31/13
      1 1/1/13 8/31/13 2/28/13
      ...
      1 1/1/13 8/31/13 8/31/13


      This query runs poorly and must be split up into a few parts as it contains much more information from t1 and spans several years. I have found that EXPAND ON can yield a very similar result, but I am having a minor issue getting the last month to be included (or the first month). Here is what I have:



      SELECT
      t1.key
      ,t1.beg_dt
      ,t1.end_dt
      ,BEGIN(prd) as end_month_dt
      FROM t1
      EXPAND ON PERIOD(t1.beg_dt, t1.end_dt) AS prd BY ANCHOR MONTH_END;


      This yields identical results except that it doesn't include the last row. If I were to use END(prd), it would exclude the first row. The issue seems to be that prd = (1/1/13, 8/31/13) and when expanded returns



      prd
      (1/31/13, 2/28/13)
      (2/28/13, 3/31/13)
      ...
      (7/31/13, 8/31/13)


      What I really need is the t1 info for all of the dates on the left hand side of each period (1/31 - 7/31) and then the last date on the right hand side (8/31). Is there another way that I can write the EXPAND ON such that I can get that result?



      Edit:
      I've found that adjusting the beg_dt and end_dt allows me to get the same results although with more functions than I'd usually like to include. It still seems to run and is still much faster than the original.



      SELECT
      t1.key
      ,t1.beg_dt
      ,t1.end_dt
      ,BEGIN(prd) as end_month_dt
      FROM t1
      EXPAND ON PERIOD(
      CASE
      WHEN beg_dt = Last_Day(beg_dt) THEN beg_dt + 1
      ELSE beg_dt
      END
      ,CASE
      WHEN end_dt = '9999-12-31' THEN end_dt
      ELSE end_dt + 1
      END) AS prd BY ANCHOR Month_End









      share|improve this question















      I am trying to rewrite a query that has a product join to expand records across a date period with the EXPAND ON function. Here is how it works currently.



      SELECT 
      t1.key
      ,MIN(t1.beg_dt)
      ,MAX(t1.end_dt)
      ,dates.end_month_dt
      FROM t1
      INNER JOIN dates
      ON t1.beg_dt < dates.end_month_dt
      AND t1.end_dt >= dates.end_month_dt
      GROUP BY 1,4;


      The dates table is just a list of a bunch of date information. end_month_dt is a column that has every end of month date going back several years. (e.g. 1/31/13, 2/28/31, 3/31/13, etc...)



      If a record in t1 has beg_dt = 1/1/13 and end_dt = 8/31/13, then this join will create a record for each month in this interval. Like this:



      key beg_dt end_dt end_month_dt
      1 1/1/13 8/31/13 1/31/13
      1 1/1/13 8/31/13 2/28/13
      ...
      1 1/1/13 8/31/13 8/31/13


      This query runs poorly and must be split up into a few parts as it contains much more information from t1 and spans several years. I have found that EXPAND ON can yield a very similar result, but I am having a minor issue getting the last month to be included (or the first month). Here is what I have:



      SELECT
      t1.key
      ,t1.beg_dt
      ,t1.end_dt
      ,BEGIN(prd) as end_month_dt
      FROM t1
      EXPAND ON PERIOD(t1.beg_dt, t1.end_dt) AS prd BY ANCHOR MONTH_END;


      This yields identical results except that it doesn't include the last row. If I were to use END(prd), it would exclude the first row. The issue seems to be that prd = (1/1/13, 8/31/13) and when expanded returns



      prd
      (1/31/13, 2/28/13)
      (2/28/13, 3/31/13)
      ...
      (7/31/13, 8/31/13)


      What I really need is the t1 info for all of the dates on the left hand side of each period (1/31 - 7/31) and then the last date on the right hand side (8/31). Is there another way that I can write the EXPAND ON such that I can get that result?



      Edit:
      I've found that adjusting the beg_dt and end_dt allows me to get the same results although with more functions than I'd usually like to include. It still seems to run and is still much faster than the original.



      SELECT
      t1.key
      ,t1.beg_dt
      ,t1.end_dt
      ,BEGIN(prd) as end_month_dt
      FROM t1
      EXPAND ON PERIOD(
      CASE
      WHEN beg_dt = Last_Day(beg_dt) THEN beg_dt + 1
      ELSE beg_dt
      END
      ,CASE
      WHEN end_dt = '9999-12-31' THEN end_dt
      ELSE end_dt + 1
      END) AS prd BY ANCHOR Month_End






      sql datetime syntax teradata






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 15:25

























      asked Nov 12 '18 at 21:08









      ackshooairy

      527




      527






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Use the begin not the end of the month as anchor and then extract the last included date:



          SELECT
          t1.key
          ,t1.beg_dt
          ,t1.end_dt
          ,Last(prd) as end_month_dt -- last included day = last day of the month
          FROM t1
          EXPAND ON PERIOD(t1.beg_dt, t1.end_dt) AS prd BY ANCHOR PERIOD MONTH_BEGIN;


          ANCHOR PERIOD is used to include the first month if beg_dt is not the first of the month.



          key beg_dt end_dt end_month_dt -- returned period 
          1 2013-01-31 2013-08-31 2013-01-31 -- (2013-01-01, 2013-02-01)
          1 2013-01-31 2013-08-31 2013-02-28 -- (2013-02-01, 2013-03-01)
          1 2013-01-31 2013-08-31 2013-03-31 -- (2013-03-01, 2013-04-01)
          1 2013-01-31 2013-08-31 2013-04-30 -- (2013-04-01, 2013-05-01)
          1 2013-01-31 2013-08-31 2013-05-31 -- (2013-05-01, 2013-06-01)
          1 2013-01-31 2013-08-31 2013-06-30 -- (2013-06-01, 2013-07-01)
          1 2013-01-31 2013-08-31 2013-07-31 -- (2013-07-01, 2013-08-01)
          1 2013-01-31 2013-08-31 2013-08-31 -- (2013-08-01, 2013-09-01)


          Edit:



          This should return the same result as your edited query (beg_date is excluded, but end_dt included while periods include the start and exclude the end):



          SELECT
          t1.KY
          ,t1.beg_dt
          ,t1.end_dt
          ,Begin(prd) AS end_month_dt
          FROM t1
          EXPAND ON PERIOD(beg_dt, end_dt) + INTERVAL '1' DAY AS prd BY ANCHOR Month_End





          share|improve this answer






















          • @dnoeth..can you share some sample results
            – stack0114106
            Nov 13 '18 at 11:46










          • @stack0114106: I just added the result.
            – dnoeth
            Nov 13 '18 at 13:13










          • thank you so much.. I didn't have access to teradata, but wanted to know how this feature works.
            – stack0114106
            Nov 13 '18 at 13:26






          • 1




            @stack0114106: It's proprietary (a bit weird) syntax for creating time series from periods: docs.teradata.com/reader/2_MC9vCtAJRlKle2Rpb0mA/…
            – dnoeth
            Nov 13 '18 at 14:41










          • This seems to have an issue when a key has records like: beg_dt = 8/1/13, end_dt = 8/8/13 beg_dt = 8/8/13, end_dt = 1/1/14 In this case, the original code ignores the first record and assigns the second to end_month_dt = 8/31/13. With the EXPAND ON, it gives the first record to 8/31/13 and the second to 9/30/13. (Don't ask me why records like this exist. I have no idea!)
            – ackshooairy
            Nov 13 '18 at 15:18











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270129%2fget-all-months-in-expand-on-in-teradata%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Use the begin not the end of the month as anchor and then extract the last included date:



          SELECT
          t1.key
          ,t1.beg_dt
          ,t1.end_dt
          ,Last(prd) as end_month_dt -- last included day = last day of the month
          FROM t1
          EXPAND ON PERIOD(t1.beg_dt, t1.end_dt) AS prd BY ANCHOR PERIOD MONTH_BEGIN;


          ANCHOR PERIOD is used to include the first month if beg_dt is not the first of the month.



          key beg_dt end_dt end_month_dt -- returned period 
          1 2013-01-31 2013-08-31 2013-01-31 -- (2013-01-01, 2013-02-01)
          1 2013-01-31 2013-08-31 2013-02-28 -- (2013-02-01, 2013-03-01)
          1 2013-01-31 2013-08-31 2013-03-31 -- (2013-03-01, 2013-04-01)
          1 2013-01-31 2013-08-31 2013-04-30 -- (2013-04-01, 2013-05-01)
          1 2013-01-31 2013-08-31 2013-05-31 -- (2013-05-01, 2013-06-01)
          1 2013-01-31 2013-08-31 2013-06-30 -- (2013-06-01, 2013-07-01)
          1 2013-01-31 2013-08-31 2013-07-31 -- (2013-07-01, 2013-08-01)
          1 2013-01-31 2013-08-31 2013-08-31 -- (2013-08-01, 2013-09-01)


          Edit:



          This should return the same result as your edited query (beg_date is excluded, but end_dt included while periods include the start and exclude the end):



          SELECT
          t1.KY
          ,t1.beg_dt
          ,t1.end_dt
          ,Begin(prd) AS end_month_dt
          FROM t1
          EXPAND ON PERIOD(beg_dt, end_dt) + INTERVAL '1' DAY AS prd BY ANCHOR Month_End





          share|improve this answer






















          • @dnoeth..can you share some sample results
            – stack0114106
            Nov 13 '18 at 11:46










          • @stack0114106: I just added the result.
            – dnoeth
            Nov 13 '18 at 13:13










          • thank you so much.. I didn't have access to teradata, but wanted to know how this feature works.
            – stack0114106
            Nov 13 '18 at 13:26






          • 1




            @stack0114106: It's proprietary (a bit weird) syntax for creating time series from periods: docs.teradata.com/reader/2_MC9vCtAJRlKle2Rpb0mA/…
            – dnoeth
            Nov 13 '18 at 14:41










          • This seems to have an issue when a key has records like: beg_dt = 8/1/13, end_dt = 8/8/13 beg_dt = 8/8/13, end_dt = 1/1/14 In this case, the original code ignores the first record and assigns the second to end_month_dt = 8/31/13. With the EXPAND ON, it gives the first record to 8/31/13 and the second to 9/30/13. (Don't ask me why records like this exist. I have no idea!)
            – ackshooairy
            Nov 13 '18 at 15:18
















          0














          Use the begin not the end of the month as anchor and then extract the last included date:



          SELECT
          t1.key
          ,t1.beg_dt
          ,t1.end_dt
          ,Last(prd) as end_month_dt -- last included day = last day of the month
          FROM t1
          EXPAND ON PERIOD(t1.beg_dt, t1.end_dt) AS prd BY ANCHOR PERIOD MONTH_BEGIN;


          ANCHOR PERIOD is used to include the first month if beg_dt is not the first of the month.



          key beg_dt end_dt end_month_dt -- returned period 
          1 2013-01-31 2013-08-31 2013-01-31 -- (2013-01-01, 2013-02-01)
          1 2013-01-31 2013-08-31 2013-02-28 -- (2013-02-01, 2013-03-01)
          1 2013-01-31 2013-08-31 2013-03-31 -- (2013-03-01, 2013-04-01)
          1 2013-01-31 2013-08-31 2013-04-30 -- (2013-04-01, 2013-05-01)
          1 2013-01-31 2013-08-31 2013-05-31 -- (2013-05-01, 2013-06-01)
          1 2013-01-31 2013-08-31 2013-06-30 -- (2013-06-01, 2013-07-01)
          1 2013-01-31 2013-08-31 2013-07-31 -- (2013-07-01, 2013-08-01)
          1 2013-01-31 2013-08-31 2013-08-31 -- (2013-08-01, 2013-09-01)


          Edit:



          This should return the same result as your edited query (beg_date is excluded, but end_dt included while periods include the start and exclude the end):



          SELECT
          t1.KY
          ,t1.beg_dt
          ,t1.end_dt
          ,Begin(prd) AS end_month_dt
          FROM t1
          EXPAND ON PERIOD(beg_dt, end_dt) + INTERVAL '1' DAY AS prd BY ANCHOR Month_End





          share|improve this answer






















          • @dnoeth..can you share some sample results
            – stack0114106
            Nov 13 '18 at 11:46










          • @stack0114106: I just added the result.
            – dnoeth
            Nov 13 '18 at 13:13










          • thank you so much.. I didn't have access to teradata, but wanted to know how this feature works.
            – stack0114106
            Nov 13 '18 at 13:26






          • 1




            @stack0114106: It's proprietary (a bit weird) syntax for creating time series from periods: docs.teradata.com/reader/2_MC9vCtAJRlKle2Rpb0mA/…
            – dnoeth
            Nov 13 '18 at 14:41










          • This seems to have an issue when a key has records like: beg_dt = 8/1/13, end_dt = 8/8/13 beg_dt = 8/8/13, end_dt = 1/1/14 In this case, the original code ignores the first record and assigns the second to end_month_dt = 8/31/13. With the EXPAND ON, it gives the first record to 8/31/13 and the second to 9/30/13. (Don't ask me why records like this exist. I have no idea!)
            – ackshooairy
            Nov 13 '18 at 15:18














          0












          0








          0






          Use the begin not the end of the month as anchor and then extract the last included date:



          SELECT
          t1.key
          ,t1.beg_dt
          ,t1.end_dt
          ,Last(prd) as end_month_dt -- last included day = last day of the month
          FROM t1
          EXPAND ON PERIOD(t1.beg_dt, t1.end_dt) AS prd BY ANCHOR PERIOD MONTH_BEGIN;


          ANCHOR PERIOD is used to include the first month if beg_dt is not the first of the month.



          key beg_dt end_dt end_month_dt -- returned period 
          1 2013-01-31 2013-08-31 2013-01-31 -- (2013-01-01, 2013-02-01)
          1 2013-01-31 2013-08-31 2013-02-28 -- (2013-02-01, 2013-03-01)
          1 2013-01-31 2013-08-31 2013-03-31 -- (2013-03-01, 2013-04-01)
          1 2013-01-31 2013-08-31 2013-04-30 -- (2013-04-01, 2013-05-01)
          1 2013-01-31 2013-08-31 2013-05-31 -- (2013-05-01, 2013-06-01)
          1 2013-01-31 2013-08-31 2013-06-30 -- (2013-06-01, 2013-07-01)
          1 2013-01-31 2013-08-31 2013-07-31 -- (2013-07-01, 2013-08-01)
          1 2013-01-31 2013-08-31 2013-08-31 -- (2013-08-01, 2013-09-01)


          Edit:



          This should return the same result as your edited query (beg_date is excluded, but end_dt included while periods include the start and exclude the end):



          SELECT
          t1.KY
          ,t1.beg_dt
          ,t1.end_dt
          ,Begin(prd) AS end_month_dt
          FROM t1
          EXPAND ON PERIOD(beg_dt, end_dt) + INTERVAL '1' DAY AS prd BY ANCHOR Month_End





          share|improve this answer














          Use the begin not the end of the month as anchor and then extract the last included date:



          SELECT
          t1.key
          ,t1.beg_dt
          ,t1.end_dt
          ,Last(prd) as end_month_dt -- last included day = last day of the month
          FROM t1
          EXPAND ON PERIOD(t1.beg_dt, t1.end_dt) AS prd BY ANCHOR PERIOD MONTH_BEGIN;


          ANCHOR PERIOD is used to include the first month if beg_dt is not the first of the month.



          key beg_dt end_dt end_month_dt -- returned period 
          1 2013-01-31 2013-08-31 2013-01-31 -- (2013-01-01, 2013-02-01)
          1 2013-01-31 2013-08-31 2013-02-28 -- (2013-02-01, 2013-03-01)
          1 2013-01-31 2013-08-31 2013-03-31 -- (2013-03-01, 2013-04-01)
          1 2013-01-31 2013-08-31 2013-04-30 -- (2013-04-01, 2013-05-01)
          1 2013-01-31 2013-08-31 2013-05-31 -- (2013-05-01, 2013-06-01)
          1 2013-01-31 2013-08-31 2013-06-30 -- (2013-06-01, 2013-07-01)
          1 2013-01-31 2013-08-31 2013-07-31 -- (2013-07-01, 2013-08-01)
          1 2013-01-31 2013-08-31 2013-08-31 -- (2013-08-01, 2013-09-01)


          Edit:



          This should return the same result as your edited query (beg_date is excluded, but end_dt included while periods include the start and exclude the end):



          SELECT
          t1.KY
          ,t1.beg_dt
          ,t1.end_dt
          ,Begin(prd) AS end_month_dt
          FROM t1
          EXPAND ON PERIOD(beg_dt, end_dt) + INTERVAL '1' DAY AS prd BY ANCHOR Month_End






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 13 '18 at 22:00

























          answered Nov 12 '18 at 22:12









          dnoeth

          44.6k31838




          44.6k31838











          • @dnoeth..can you share some sample results
            – stack0114106
            Nov 13 '18 at 11:46










          • @stack0114106: I just added the result.
            – dnoeth
            Nov 13 '18 at 13:13










          • thank you so much.. I didn't have access to teradata, but wanted to know how this feature works.
            – stack0114106
            Nov 13 '18 at 13:26






          • 1




            @stack0114106: It's proprietary (a bit weird) syntax for creating time series from periods: docs.teradata.com/reader/2_MC9vCtAJRlKle2Rpb0mA/…
            – dnoeth
            Nov 13 '18 at 14:41










          • This seems to have an issue when a key has records like: beg_dt = 8/1/13, end_dt = 8/8/13 beg_dt = 8/8/13, end_dt = 1/1/14 In this case, the original code ignores the first record and assigns the second to end_month_dt = 8/31/13. With the EXPAND ON, it gives the first record to 8/31/13 and the second to 9/30/13. (Don't ask me why records like this exist. I have no idea!)
            – ackshooairy
            Nov 13 '18 at 15:18

















          • @dnoeth..can you share some sample results
            – stack0114106
            Nov 13 '18 at 11:46










          • @stack0114106: I just added the result.
            – dnoeth
            Nov 13 '18 at 13:13










          • thank you so much.. I didn't have access to teradata, but wanted to know how this feature works.
            – stack0114106
            Nov 13 '18 at 13:26






          • 1




            @stack0114106: It's proprietary (a bit weird) syntax for creating time series from periods: docs.teradata.com/reader/2_MC9vCtAJRlKle2Rpb0mA/…
            – dnoeth
            Nov 13 '18 at 14:41










          • This seems to have an issue when a key has records like: beg_dt = 8/1/13, end_dt = 8/8/13 beg_dt = 8/8/13, end_dt = 1/1/14 In this case, the original code ignores the first record and assigns the second to end_month_dt = 8/31/13. With the EXPAND ON, it gives the first record to 8/31/13 and the second to 9/30/13. (Don't ask me why records like this exist. I have no idea!)
            – ackshooairy
            Nov 13 '18 at 15:18
















          @dnoeth..can you share some sample results
          – stack0114106
          Nov 13 '18 at 11:46




          @dnoeth..can you share some sample results
          – stack0114106
          Nov 13 '18 at 11:46












          @stack0114106: I just added the result.
          – dnoeth
          Nov 13 '18 at 13:13




          @stack0114106: I just added the result.
          – dnoeth
          Nov 13 '18 at 13:13












          thank you so much.. I didn't have access to teradata, but wanted to know how this feature works.
          – stack0114106
          Nov 13 '18 at 13:26




          thank you so much.. I didn't have access to teradata, but wanted to know how this feature works.
          – stack0114106
          Nov 13 '18 at 13:26




          1




          1




          @stack0114106: It's proprietary (a bit weird) syntax for creating time series from periods: docs.teradata.com/reader/2_MC9vCtAJRlKle2Rpb0mA/…
          – dnoeth
          Nov 13 '18 at 14:41




          @stack0114106: It's proprietary (a bit weird) syntax for creating time series from periods: docs.teradata.com/reader/2_MC9vCtAJRlKle2Rpb0mA/…
          – dnoeth
          Nov 13 '18 at 14:41












          This seems to have an issue when a key has records like: beg_dt = 8/1/13, end_dt = 8/8/13 beg_dt = 8/8/13, end_dt = 1/1/14 In this case, the original code ignores the first record and assigns the second to end_month_dt = 8/31/13. With the EXPAND ON, it gives the first record to 8/31/13 and the second to 9/30/13. (Don't ask me why records like this exist. I have no idea!)
          – ackshooairy
          Nov 13 '18 at 15:18





          This seems to have an issue when a key has records like: beg_dt = 8/1/13, end_dt = 8/8/13 beg_dt = 8/8/13, end_dt = 1/1/14 In this case, the original code ignores the first record and assigns the second to end_month_dt = 8/31/13. With the EXPAND ON, it gives the first record to 8/31/13 and the second to 9/30/13. (Don't ask me why records like this exist. I have no idea!)
          – ackshooairy
          Nov 13 '18 at 15:18


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53270129%2fget-all-months-in-expand-on-in-teradata%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          ReactJS Fetched API data displays live - need Data displayed static

          政党