Last Day of Prior Months Calculationselecting records that are 3 days from expiring datetimeFill in missing...

Calculate Levenshtein distance between two strings in Python

Is there a way to make member function NOT callable from constructor?

Landlord wants to switch my lease to a "Land contract" to "get back at the city"

Eliminate empty elements from a list with a specific pattern

Imbalanced dataset binary classification

Travelling to Edinburgh from India

Is it legal to have the "// (c) 2019 John Smith" header in all files when there are hundreds of contributors?

How is it possible for user's password to be changed after storage was encrypted? (on OS X, Android)

What does 'script /dev/null' do?

How can I fix this gap between bookcases I made?

My colleague's body is amazing

Can I find out the caloric content of bread by dehydrating it?

How did the USSR manage to innovate in an environment characterized by government censorship and high bureaucracy?

Is every set a filtered colimit of finite sets?

Symmetry in quantum mechanics

How to manage monthly salary

Why is my log file so massive? 22gb. I am running log backups

Why do we use polarized capacitors?

LM317 - Calculate dissipation due to voltage drop

Need help identifying/translating a plaque in Tangier, Morocco

Why doesn't a const reference extend the life of a temporary object passed via a function?

Can a planet have a different gravitational pull depending on its location in orbit around its sun?

Crop image to path created in TikZ?

Does it makes sense to buy a cycle to learn riding?



Last Day of Prior Months Calculation


selecting records that are 3 days from expiring datetimeFill in missing dates with data value from previous populated date for groupUpdating total using values from previous row - SQL Server 2016Sybase IQ cannot select by a calculated dateWhat is the correct method to pass range of dates to a SQL Server 2016 temporal table query where you need a set returned for each day?Improve performance of while loop for INSERT INTO query?Calculate drawdown and volatility on 3 yearsFiscal Year to Date filterHow can I use mysql to determine the Sundays for the last year?how to count distinct value per day with start time and end time






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I may be overthinking this one, but I can't seem to find the correct code for identifying the last day of previous months in a table that appends daily. For example, I have a table that appends records daily and I'm trying to set the date filter for 1/31/2019 or 2/28/2019 or 3/31/2019.



In the past I've only needed the max date available in the table (SELECT(MAX(ROW_PROCESSED_THRU) FROM dbo.TA_CUSTOMER_FILE)










share|improve this question























  • "set the date filter" - what do you mean?

    – Aaron Bertrand
    11 mins ago











  • Using the same table, I need to pull certain data elements from the last day of the month prior (3/31/2019) and then other data elements from the same table but from 2/28/2019

    – Mike Jones
    2 mins ago











  • Show your table structure, some sample data, and desired results, please. Word problems are hard to solve technically.

    – Aaron Bertrand
    38 secs ago


















0















I may be overthinking this one, but I can't seem to find the correct code for identifying the last day of previous months in a table that appends daily. For example, I have a table that appends records daily and I'm trying to set the date filter for 1/31/2019 or 2/28/2019 or 3/31/2019.



In the past I've only needed the max date available in the table (SELECT(MAX(ROW_PROCESSED_THRU) FROM dbo.TA_CUSTOMER_FILE)










share|improve this question























  • "set the date filter" - what do you mean?

    – Aaron Bertrand
    11 mins ago











  • Using the same table, I need to pull certain data elements from the last day of the month prior (3/31/2019) and then other data elements from the same table but from 2/28/2019

    – Mike Jones
    2 mins ago











  • Show your table structure, some sample data, and desired results, please. Word problems are hard to solve technically.

    – Aaron Bertrand
    38 secs ago














0












0








0








I may be overthinking this one, but I can't seem to find the correct code for identifying the last day of previous months in a table that appends daily. For example, I have a table that appends records daily and I'm trying to set the date filter for 1/31/2019 or 2/28/2019 or 3/31/2019.



In the past I've only needed the max date available in the table (SELECT(MAX(ROW_PROCESSED_THRU) FROM dbo.TA_CUSTOMER_FILE)










share|improve this question














I may be overthinking this one, but I can't seem to find the correct code for identifying the last day of previous months in a table that appends daily. For example, I have a table that appends records daily and I'm trying to set the date filter for 1/31/2019 or 2/28/2019 or 3/31/2019.



In the past I've only needed the max date available in the table (SELECT(MAX(ROW_PROCESSED_THRU) FROM dbo.TA_CUSTOMER_FILE)







sql-server-2016 date






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 13 mins ago









Mike JonesMike Jones

454




454













  • "set the date filter" - what do you mean?

    – Aaron Bertrand
    11 mins ago











  • Using the same table, I need to pull certain data elements from the last day of the month prior (3/31/2019) and then other data elements from the same table but from 2/28/2019

    – Mike Jones
    2 mins ago











  • Show your table structure, some sample data, and desired results, please. Word problems are hard to solve technically.

    – Aaron Bertrand
    38 secs ago



















  • "set the date filter" - what do you mean?

    – Aaron Bertrand
    11 mins ago











  • Using the same table, I need to pull certain data elements from the last day of the month prior (3/31/2019) and then other data elements from the same table but from 2/28/2019

    – Mike Jones
    2 mins ago











  • Show your table structure, some sample data, and desired results, please. Word problems are hard to solve technically.

    – Aaron Bertrand
    38 secs ago

















"set the date filter" - what do you mean?

– Aaron Bertrand
11 mins ago





"set the date filter" - what do you mean?

– Aaron Bertrand
11 mins ago













Using the same table, I need to pull certain data elements from the last day of the month prior (3/31/2019) and then other data elements from the same table but from 2/28/2019

– Mike Jones
2 mins ago





Using the same table, I need to pull certain data elements from the last day of the month prior (3/31/2019) and then other data elements from the same table but from 2/28/2019

– Mike Jones
2 mins ago













Show your table structure, some sample data, and desired results, please. Word problems are hard to solve technically.

– Aaron Bertrand
38 secs ago





Show your table structure, some sample data, and desired results, please. Word problems are hard to solve technically.

– Aaron Bertrand
38 secs ago










1 Answer
1






active

oldest

votes


















0














First day of this month is simply:



SELECT DATEADD(DAY, -DAY(GETDATE()), CONVERT(date, GETDATE()));


From there it is easy to derive the beginning of the previous month. You don't need the end of the month; stop thinking about the end of a period. You need everything greater than or equal to the beginning of the period, and less than the end of the next period. So:



DECLARE @fdtm date = DATEADD(DAY, -DAY(GETDATE()), CONVERT(date, GETDATE()));

SELECT ... FROM ...
WHERE DateColumn >= DATEADD(MONTH, -1, @fdtm)
AND DateColumn < @ftdm;




share
























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "182"
    };
    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: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    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%2fdba.stackexchange.com%2fquestions%2f234237%2flast-day-of-prior-months-calculation%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














    First day of this month is simply:



    SELECT DATEADD(DAY, -DAY(GETDATE()), CONVERT(date, GETDATE()));


    From there it is easy to derive the beginning of the previous month. You don't need the end of the month; stop thinking about the end of a period. You need everything greater than or equal to the beginning of the period, and less than the end of the next period. So:



    DECLARE @fdtm date = DATEADD(DAY, -DAY(GETDATE()), CONVERT(date, GETDATE()));

    SELECT ... FROM ...
    WHERE DateColumn >= DATEADD(MONTH, -1, @fdtm)
    AND DateColumn < @ftdm;




    share




























      0














      First day of this month is simply:



      SELECT DATEADD(DAY, -DAY(GETDATE()), CONVERT(date, GETDATE()));


      From there it is easy to derive the beginning of the previous month. You don't need the end of the month; stop thinking about the end of a period. You need everything greater than or equal to the beginning of the period, and less than the end of the next period. So:



      DECLARE @fdtm date = DATEADD(DAY, -DAY(GETDATE()), CONVERT(date, GETDATE()));

      SELECT ... FROM ...
      WHERE DateColumn >= DATEADD(MONTH, -1, @fdtm)
      AND DateColumn < @ftdm;




      share


























        0












        0








        0







        First day of this month is simply:



        SELECT DATEADD(DAY, -DAY(GETDATE()), CONVERT(date, GETDATE()));


        From there it is easy to derive the beginning of the previous month. You don't need the end of the month; stop thinking about the end of a period. You need everything greater than or equal to the beginning of the period, and less than the end of the next period. So:



        DECLARE @fdtm date = DATEADD(DAY, -DAY(GETDATE()), CONVERT(date, GETDATE()));

        SELECT ... FROM ...
        WHERE DateColumn >= DATEADD(MONTH, -1, @fdtm)
        AND DateColumn < @ftdm;




        share













        First day of this month is simply:



        SELECT DATEADD(DAY, -DAY(GETDATE()), CONVERT(date, GETDATE()));


        From there it is easy to derive the beginning of the previous month. You don't need the end of the month; stop thinking about the end of a period. You need everything greater than or equal to the beginning of the period, and less than the end of the next period. So:



        DECLARE @fdtm date = DATEADD(DAY, -DAY(GETDATE()), CONVERT(date, GETDATE()));

        SELECT ... FROM ...
        WHERE DateColumn >= DATEADD(MONTH, -1, @fdtm)
        AND DateColumn < @ftdm;





        share











        share


        share










        answered 8 mins ago









        Aaron BertrandAaron Bertrand

        154k18298493




        154k18298493






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Database Administrators Stack Exchange!


            • 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%2fdba.stackexchange.com%2fquestions%2f234237%2flast-day-of-prior-months-calculation%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

            Parapolítica Índice Antecedentes El escándalo Proceso judicial Consecuencias Véase...

            How to remove border from elements in the last row?Targeting flex items on the last rowHow to vertically wrap...

            Tecnologías entrañables Índice Antecedentes Desarrollo Tecnologías Entrañables en la...