I am new to Informix. I tried creating timeseries calendar pattern which should store data only for weekdays (Monday-Friday).
I inserted the data below for that into CalendarPatterns table:
INSERT INTO CalendarPatterns (cp_name, cp_pattern)
VALUES ('5day_ptrn', '{1 off, 5 on, 1 off}, day');
While trying to inserting record into a table which is using this calendar pattern, it's storing data for Saturday and Sunday but not storing data for Thursday and Friday.
Please advise where I am going wrong.
Related
I am trying to create a Attendance result set in SQL Server for using it in a SSRS report. The Employee Attendance table is as below:
EmpId
ADate
In
Out
1
2023-01-01
8:00
15:00
I need to calculate the Total working days for all months in a year and display the number of working days per employee. Report format should be as follows:
Saturday and Sunday being weekend, I can able to get the no of working days monthly.
Another table tbl_Holiday has entries for holidays Fromdate and ToDate. I need to consider that also when calculating working days. Several number of results i got from the internet for calculating this. But when creating a view using this data , it has to calculate workdays for each employee row
SELECT
EmpName, EmpId,
(SELECT COUNT(*) FROM tbl_EmpAttendance
WHERE EmpRecId = A.RecId
GROUP BY MONTH(Adate), YEAR(Adate)) AS WorkedDays,
dbo.fn_GetWorkDays(DATEFROMPARTS(YEAR(ADate), MONTH(ADate), 1), EOMONTH(ADate)) AS workingDays
FROM
tbl_Employee A
LEFT JOIN
tbl_EmpAttendance B ON A.RecId = B.EmpRecId
fn_GetWorkDays - calculates the working days for month.
I need to get number of holidays from tbl_holiday too, I understand that this query is becoming more complex than I thought. There must be simpler way to achieve this, can anyone please help?
I tried to get the result in one single view, for using that as SSRS report dataset
I have a cronjob that looks at load previous day data sourcing another table that gets refreshed on a daily basis. I am looking to update the job to source from origination table that holds entire year of data. However I am just looking to capture and load previous 1 day of data from the origination table. The origination table has a date updated field which is in timestamptz format (ex - 2022-08-01 20:20:20.736+00). Any recommendation on what function to place where the job picks up:
last_updated from >= 2022-08-01 10:00:00 and last_updated from <= 2022-08-02 10:00:00. Assuming I am running this on 2022-08-02 11:00:00.
Thanks,
Snowflake Database:
I have a day level table , i am trying use the day column to create a week column with the value of first Monday's of the week as a week value using following function. even though the table have a data for all seven days ( Monday through Sunday ) of the week. The following function will create a week column with five working days ( Monday through Friday) only rolled up to a week leaving Saturday and Sunday. is there any function which i can use to grab all seven days of data under one week in SNOWFLAKE DATABASE (first monday of the week).
CURRENT FUNCTION USED:
select dateadd('day', (extract('dayofweek_iso', current_date()) * -1) +1 , current_date() );
Snowflake provides DATE_TRUNC() to roll up date to corresponding year/month/week/day.
For the mentioned use case following query will roll up to Monday of the week.
select date_trunc('WEEK',current_date()) ;
Snowflake last_day() function can be used to achieve that. You can easily get the last day of week (Sunday) and subtract 6 days to get the first day of that week (Monday) like that:
select last_day(current_date(), 'week')-6 as first_day_of_week;
I'm creating a query that runs daily, and pushes data to the following tables:
Daily Dashboard
Weekly Dashboard
Monthly Dashboard
Yearly Dashboard
The daily file pushes data to the other 3 tables and is dropped daily. What I'm trying to figure out is how to put a trigger/command into the drop table command for the weekly and monthly tables.
The Weekly File Needs to Drop every Monday
And
The Monthly File needs to Drop on the 1st Day of each month
I'm assuming I'd need to have some sort of declaration like
DECLARE #CurrentMonth as date SET #CurrentMonth = month(GetDate())
DECLARE #CurrentWeek as date SET #CurrentWeek = week(GetDate())
And then compare the current week/month against the date the table was created
eg:
IF CurrentWeek > CreatedWeek - Drop Table
IF CurrentMonth > CreatedMonth - Drop Table
Does anyone know if thats achievable, or if there is a better way of going about this?
Any help/advice is appreciated
What is the best way in SSIS and which transformation(s) should I use to change (update) dates from Sundays to the previous Friday with the exception of the 1st day of the month. The exception would then do an Update to change the date to Monday.
I would also then need an update to change dates that are on certain Holidays like Thanksgiving and Christmas to the previous day, unless of course that day is a Sunday.
I know how to find these dates using SQL, but I'm somewhat of a newbie in SSIS and not sure how this works using transformations or what the best method would be.
For reference, using SQL I use this to identify the dates within a month that are Sundays. I then do an update to change those to either Fridays, or like I said, if that causes it go outside of the current month to Mondays:
SELECT * FROM DriverRoutes
where [Date] BETWEEN dateadd(month,datediff(month,0,'1/1/2014')-1,0)
AND dateadd(ms,-3,DATEADD(mm, DATEDIFF(mm,0, '1/1/2014'), 0))
and DATEPART(w,[Date]) = '1'
update DriverRoutes
set DATEPART(w,[Date]) = '6'
where DATEPART(w,[Date]) = '1'
etc.... And then I also change dates manually when they are on Holidays, but don't want to do that each month anymore.
Thanks in advance!
Create a calendar table that holds a list of dates and their business meanings. The dates that are recognized locally as holidays, and the holidays that are recognized by a business are in constant flux. Instead of embedded formulas, you end up with easy-to-read code.
UPDATE t1
SET [DeliveryDate] = t2.[NextBusinessDay]
FROM DriverRoutes t1
INNER JOIN Calendar t2 ON (t1.[Date] = t2.[Date])
WHERE t2.[IsHoliday] = 1