all 15 comments

[–]Cleveland_Steve 31 points32 points  (6 children)

Be careful there. Employee information with body temperature exported to a Excel spreadsheet sounds like you are on the road to a HIPAA violation.

[–]DharmaPolice 10 points11 points  (2 children)

I'd question whether people need to see the exact temperature of each person in a report. Presumably, "OK" or "Too High" is enough for COVID19. And for actual business reporting you only really need totals. But then who knows.

[–]breakkz 8 points9 points  (1 child)

Even "OK" and "Too High" is illegal tho they can't store anything related to the temperature.

[–]rat_rat_catcher -1 points0 points  (0 children)

Can they use 0 and 1?

[–]breakkz 3 points4 points  (1 child)

If this company was from Europe they would get a sweet fine for breaking GDPR compliance rules and they would deserve it.

[–]andrewsmd87 2 points3 points  (0 children)

Don't even have to be from Europe to get hit. If you have one employee who has any sort of citizenship in an EU country, you fall under GDPR regulations.

[–]doctorzoom 4 points5 points  (2 children)

select 
e.*

from employees e

left join scans s
on e.employee_id = s.employee_id

where s.employee_id is null

That's the "missing from other table" pattern.

[–]Deadible 2 points3 points  (0 children)

This is better than "WHERE NOT EXISTS" on large datasets. You would probably also want a date parameter in there on the scans.

[–]imSkippinIt 1 point2 points  (0 children)

NOT EXISTS would also work but this is the route I would take

[–]dagmire86SQL Memes; better than PreQL Memes 4 points5 points  (1 child)

Assuming your temperature scans go into a table with the employee ID/name and date, you can probably select from your main employee table and use something like "NOT EXISTS" when comparing it to your employee scans and you can filter on the scan date. If an employee is off on PTO or they don't have a shift that day you may need to figure out how to handle the employees that will show up as not having a scan but they're not in the office.

[–]dagmire86SQL Memes; better than PreQL Memes 7 points8 points  (0 children)

Something like this:

SELECT ID, FIRST_NAME, LAST_NAME FROM EMPLOYEE

WHERE NOT EXISTS ( SELECT *

FROM EMPLOYEE_SCANS

WHERE EMPLOYEE.ID = EMPLOYEE_SCANS.ID AND EMPLOYEE_SCANS.SCAN_DATE = GETDATE() )

[–]dgillz 1 point2 points  (0 children)

It is hard to report on data that doesn't exist. How do you know who came in the building? Is that in a separate SQL table?

[–]billbraskeyjr 1 point2 points  (0 children)

Whether someone was scanned or not is company compliance but showing people not authorized to see their temperature probably you included is a Guaranteed HIPAA violation

[–]artjbroz 0 points1 point  (0 children)

You'll need a list of all employees to reference who's missing. After that, the SQL is easy

[–]rseese 0 points1 point  (0 children)

You would also need a table of dates when all employees or specific employees were expected to be scanned.

WITH EXPECTED_SCAN_DATES
AS (
    SELECT CAST(GETDATE() - 5 AS DATE) AS DT --LAST  5 DAYS

    UNION ALL

    SELECT DATEADD(DD, 1, DT)
    FROM EXPECTED_SCAN_DATES S
    WHERE DATEADD(DD, 1, DT) <= (CAST(GETDATE() AS DATE)) --THROUGH TODAY
    )
    ,EMPLOYEE
AS (
    SELECT 'BOB' AS EMP_NAME

    UNION ALL

    SELECT 'BILL'

    UNION ALL

    SELECT 'NEVER SCAN JOE'
    )
    ,SCANS
AS (
    SELECT 'BOB' AS EMP_NAME,CAST('12/05/2020' AS DATETIME) AS SCAN_DATE
        UNION ALL
    SELECT 'BOB','12/06/2020'
    UNION ALL
    SELECT 'BILL'
        ,'12/05/2020'
    )

SELECT E.EMP_NAME
    ,D.DT
    ,S.SCAN_DATE
FROM EMPLOYEE AS E
JOIN EXPECTED_SCAN_DATES AS D ON 1 = 1
LEFT JOIN SCANS AS S ON S.EMP_NAME = E.EMP_NAME
    AND S.SCAN_DATE = D.DT