SSIS Package to archive data on monthly basis - sql

Can any one let me know how can i create a ssis package which will serve the below mentioned criteria.
1) Extract new member joiner data on monthly basis .
2) Store the data on a separate table call 'Joiner' which has column member_name,join_date,member_class.
3) the job will be scheduled to run 1st day of every month.
For example the package will run on 1st April with a join_date 1st March to 31st Match and dump it to the 'joiner' table. Next month it will run on 1st May with a join_date of 1st April to 30th April.
I know i have to create a store procedure with a join date parameter to pass but my concern is how should i achieve this automation of passing date every month and archive joiners data on month and month basis.
Any help will be much appreciated.

It sounds like your question is about how to get the previous month of data on an automated basis. DATEADD() and EOMONTH() can accomplish your need of grabbing a rolling timeframe each month automatically if you are using SQL Server.
SELECT
getdate(), --current date
EOMONTH(GETDATE()), --last day of the current month
EOMONTH(GETDATE(),-1), --last day of the previous month
DATEADD(DAY, 1, EOMONTH(GETDATE(),-2)) --go back two months and add 1 day
Your query would need to include something like this in the WHERE clause.
WHERE join_date >= DATEADD(DAY, 1, EOMONTH(GETDATE(),-2))
AND join_date < EOMONTH(GETDATE(),-1)

Related

Amazon Redshift- How to get start date of the Week from existing daily date field from the table?

I am trying to get start date of the week from existing daily date field from the same table. For example daily dates from 05/08/2022 to 05/14/2022 , the start of the week date output need to come as 05/08/2022 for all days in the week. week start on Sunday.
Also similar thing require to first date of the Month and quarter(3 month division)
The date_trunc() function performs this operation - https://docs.aws.amazon.com/redshift/latest/dg/r_DATE_TRUNC.html

Need help aggregating custom months into a snapshot field

I am working with a dataset that has a continues date field and I want to aggregate it at a monthly level where the month ends on the 15th day of the month. So each snapshot date would go from the 15th of the month to the 14th of the following month.
Example: Snapshot Date = 7/15/2021 would correspond with the date range of 6/15/2021 through 7/14/2021.
Is there an easy way to do this for all months in the table using SQL Server.
Just subtract 14 days and convert to a year/month format. One trick is to move everything to the last day of the month:
select eomonth(dateadd(day, -14, datecol)), count(*)
from t
group by eomonth(dateadd(day, -14, datecol));

Snowflake retrieving data of past month on a particular date of current month

I am new to snowflake and my manager wants me to retrieve the data of the past month when it is 5th of the current month. For example if today is 5th April, then ask snowflake to retrieve the data of the past month i.e. from 1st March 2021 to 31st March 2021 and similar for all the other months.
The reason why he wants to update the last month data on 5th of every next month because that is the day when we get the data.
I tried to use the DATEADD function but it is more complicated than just using this function.
Thanks in advance!
PS: The data for every month has same date. for example: the date is like - April 20th will be stored in the database as "2021-4-01" - and same for April 25th date will be stored as "2021-4-01" .
The day doesn't change in the database, just the month and year.
as to the prior month window that can be done via DATE_TRUNC and DATEADD
select
current_date as cd
,date_trunc('month', cd) as end_range
,dateadd('month', -1, end_range) as start_range
;
gives:
CD END_RANGE START_RANGE
2021-04-21 2021-04-01 2021-03-01
the other half of the question only do it on the 5th, if you have a task run daily etc. can be solved via
,day(current_date) = 5 as is_the_fifth
or if in an inline way
iff(day(current_date) = 5, <do true stuff>, <do false stuff>)

Adding and Updating data by month in Access with Vb.Net

I've been trying to add and update data to a table in MS Access by month. This is so I can calculate any expenditures or sales per month. So if stock for a company were bought in March It would add this to the March expenditure row. And would be kept different from the expenditure in February or April for example.
I am unsure how to do this and how to have my program check the current month and year to see where it should input the data/make a new row for the month.
I know how to write to a database, I'm just not sure how to make my program write to a row in the database that depends on the current month and year
Any help would be greatly appreciated and sorry If this is all long winded or this is an easy fix, its my first post here and I'm a novice when it comes to programming.
In Access, to get the current date you use the date() function. I.E. if you were to do:
SELECT DATE()
the query would return the system date, which, today would be:
26/03/2015
To do math (add or subtract a specified interval) against the date, the syntax, again in Access, is:
DATEADD([Interval],[Number],[Date])
So, if I wanted to add one month to the current date I would write:
DATEADD(m, 1, DATE())
Or conversely, subtract two months from the current date:
DATEADD(m, -2, DATE())

SQL Date Issue for Weekly Report Data

I need to run a weekly report based on the arrival date. How can I set the arrival date in the where clause so that I can get the result only for each week. The hard part is I DO NOT want to modify the dates each week. I need the permanent where clause for the date. I have to provide a list of customers who arrived every week and I just want to run the same script without changing the week dates.
Please assist.
Thanks.
SELECT * FROM TABLE WHERE
(ARRIVAL_DATE>DATEFROMPARTS(YEAR(GETDATE()-7), MONTH(GETDATE()-7), DAY(GETDATE()-7)))//7 days before starting at midnight
AND
(ARRIVAL_DATE<DATEFROMPARTS(YEAR(GETDATE()), MONTH(GETDATE()), DAY(GETDATE()))) //NOW in the YYYY, MM,DD format
This will get everything that happened in the current calendar week (Mon-Sun)
SELECT * FROM Table1
WHERE ArrivalDate BETWEEN
CAST(DATEADD(dd,(((DATEPART(dw,getdate())+##DATEFIRST) % 7)+5) % 7 ,getdate()) as date) AND
CAST(DATEADD(dd,6+((((DATEPART(dw,getdate())+##DATEFIRST) % 7)+5) % 7 ),getdate()) as date)
Edit - Removed extra E in BETWEEN