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;
}
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
add a comment |
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
"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
add a comment |
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
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
sql-server-2016 date
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
add a comment |
"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
add a comment |
1 Answer
1
active
oldest
votes
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;
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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;
add a comment |
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;
add a comment |
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;
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;
answered 8 mins ago
Aaron Bertrand♦Aaron Bertrand
154k18298493
154k18298493
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
"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