Create an update column for alert system in SQL-server/SSRS - sql

I wish to create an online alert system in SSRS visual studio. meaning I have 2 online SQL queries that gives me online data about people present:
TABLE 1 example: People waiting for X more then 8 hours:
Name Waiting_Time
------------------------------
Brian 08:45
TABLE 2 example: People waiting for Y more then 4 hours:
Name Waiting_Time
------------------------------------
Danielle 04:23
Ari 06:56
I've created an SSRS report that shows both tables and their waiting time online at the moment the report is opened.
What I want is to create an alert for every NEW row enters one of the tables. how can I do it? I thought maybe SQL-wise by entering an ETL DATE/ a date of which the row entered the table (How can I do it? - in SQL) and then create an alert every 15 min for all values with ETL\a date of which the row entered the table (update date) new from the past 15 min.. how can I do it on SQL?? please help with that...
desirable output:
Name Waiting_Time Enter_Date (the time key in which he entered the table)
-------------------------------------------------------------
Brian 08:45 2023-01-29 22:46
maybe theres an other way?
would love for some advise and help!

Related

I would like to know if there's a way to complete this query

I'm trying to obtain the average time of an "activity" in a moodle database, i am not an sql expert, but i have managed to get to the point showed in the picture, my question is if exists a way to obtain, first the timestamp/time difference (this "activity" does not have a starting time column like many others) by day and then sum them all to get the average of that activity , for the first i tried with the function 'EXTRACT()' and comparing the dates in the format "%Y-%m-%d" but only sums the first row where they are equal, by the way i have been doing this just by a sql statement, i know the existence of store procedures but my level of sql is not that high.
Thanks in advance!
data obtained so far
Data on table logs (the most important i think)
component
action
objecttable
userid
courseid
timecreated
mod_quiz*
viewed
quiz_attempts
6
2
1645287525
mod_forum
viewed
forum
5
2
1645288525
core
loggedout
user
2
0
1645291745
mod_page
viewed
page
5
2
1645291955
Data i've trying to get:
Activity
StartTime
EndTime
Total
forum
19:01
19:10
9 minute(s)
quiz
15:45
16:00
15 minute(s)
page
...
...
...
workshop
...
...
...
but so far i get to assort the data in a column
Time
2022-x-x h:m
....
but when i try to sum by day with the function EXTRACT() and trying to match the dates in a very long query it just get the first record.
NOTE: * half of the "activities" were easy to calculate since they have a "timestart" and "timeend" columns but i can not figure out how to solve the ones that do not have a "timestart" column.

Amount of overlaps per minute

I would like to make an SQL-Statement in order to find the amount of users that are using a channel by date and time. Let me give you an example:
Let's call this table Data:
Date Start End
01.01.2020 17:00 17:30
01.01.2020 17:01 17:03
01.01.2020 17:29 18:30
Data is a table that shows when an user started the connection on a channel and the time the connection was closed. A connection can be made any time, which means from 00:00 until the next day.
What I am trying to achieve is to count the maximum number of connections that were made over a big period if time. Let's say 1st February to 1st April.
My idea was to make another table with timestamps in Excel. The table would display a Timestamp for every Minute in a specific date.
Then I tried to make a statement like:
SELECT *
FROM Data,Timestamps
WHERE Timestamps.Time BETWEEN Data.Start AND Data.End.
Now logically this statement does what is supposed to do. The only problem is that it is not really performant and therefore not finishing. With the amount of timestamps and the amount of data I have to check it is not able to finish.
Could anybody help me with this problem? Any other ideas I can try or how to improve my statement?
Regards!
So why dou you create another table in Excel and not directly in MS Access and then why won't you set up the indexes of the timestamps right. That will speed it up by factors.
By the way I think that your statement will print repeat every user that happened to match your Start .. End period, so the amount of rows produced will be enormous. You shall rather try
SELECT Timestamps.Time, COUNT(*)
FROM Data,Timestamps
WHERE Timestamps.Time BETWEEN Data.Start AND Data.End
GROUP BY Timestamps.Time;
But sorry if the syntax in MS Access is different.

Match records and perform date calculations within same query?

This referes to a question i asked yesterday which didn't get solved. I have now simplified my tables so the question can be answered, but need some further help.
I have a table called chd18 (100,000+ records), which contains records of 18+ patients with a disease CHD.
ID|Age|indexdate
1 20 11/05/2013
2 25 19/10/2012
3 44 07/12/2013
4 85 01/01/2014
I then have another table (died1216) with all patients (500,000+ records) that have died between April 2012-March 2016
ID|Age|deathdate
2 25 20/10/2012
4 85 03/01/2015
What I want to do is create another table where I check if any of the CHD18 patients have died between April 2012-March 2016 (table died1216), if so, is the difference between indexdate and deathdate >=12 months.
Essentially that table should look like this
ID|Age|indexdate|deathdate
4 85 01/01/2014 03/01/2015
I know a join between these 2 tables are needed on the ID, but not sure how to achieve this, especially checking if 12months has passed between the 2 dates.
Please can someone kindly assist.
For anyone saying the answer is in my previous question, can you kindly explain how the indexdate and deathdate are being compared for 12months or more? because i see it being compared to currentdate - interval '1 year'??
Thanks

query for non-existant value in access

I am trying to create an access query that will report when someone misses a task, based on the fact that there is no record for that task for a shift.
I have a table that records task completion basic fields are:
Date
Shift
Task
Tech
when the tech completes a task, a record is created logging the event.
I need to be able to pull a query that identifies when a shift misses a task.
I have tried an unmatched query to no avail using a sample table with shifts as its only data, and even tried adding the task to this table.
so I am looking for some SQL help.
there has to be a way to do this...
Is it something like
SELECT Date, Shift, Task, Tech
WHERE Shift IS NOT NULL AND Task IS NULL
If we make the assumption (i know.. that's dangerous) that you have a seperate shift table, and the shift in the list you are looking for is a foreign key. I think you are looking for a shift ID that has no assciated task. You can a use a join and search for null values on your task table.
example:
SELECT shifttable.shift, Tasktable.task, tasktable.tech, tasktable.date
FROM shiftTable
LEFT JOIN TaskTable
ON TaskTable.ShiftID = shiftTable.ShiftID
WHERE TaskTable.PrimaryKey IS NULL
Given the Data:
Shift Table:
ShiftID Shift
1 Monday
2 Tuesday
3 Wednesday
Task Table
TaskID ShiftID Date tech task
1 1 5/15/15 bob job 1
2 3 5/22/15 Sam job 4
would yeild the results:
Shift
Tuesday

Crystal report: Count based on date

currently I'm in midst of developing crystal report template. Any help is much appreciated.
What I want to achieve is to count based on date.
I give example.
I got 3 params:
start period(date): eg: 1/5/2013
end period: eg: 5/5/2013(date)
how many working days(number): eg: 5
and the table is like this
name working date
nameA 2/5/2013
2/5/2013
3/5/2013
nameB 2/5/2013
4/5/2013
5/5/2013
I want it to count how many working days for each name.
Eg result: nameA: 2 working days, nameB: 3 working days.
Please help. I'm new to programming..:( Couldn't think any programming design for this..
You need this query,
select name, count(distinct working_date)
from table where working_date between ? and ?
but most of all, you need to learn SQL. It is impossible to write reports without some knowledge of SQL.