Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL Query to exclude a certain user on a certain day

I’m trying to write a SQL query which will be used in an SSRS report.
It is to show the number of changes made to a table by a user between two dates.
I have the query working fine except when I try to remove all entries by a certain user on a certain day as these were done to cleanse the data and will skew the values.

The WHERE clause I have tried is as follows:

WHERE
(DATEADD(MONTH, DATEDIFF(MONTH, 0, Hist.Timestamp), 0) >= @FromDate)
AND
(DATEADD(MONTH, DATEDIFF(MONTH, 0, Hist.Timestamp), 0) < @ToDate)
AND
(Hist.Timestamp <> '2022-04-26' AND Hist.UserId <> 'DOMAIN\John.Smith')

But this removes all entries by that user and not just entries by that user on that day.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How can I edit this WHERE clause to to exclude the results which are for both items?

Thanks,
Paul

>Solution :

...AND NOT (hist.timestamp = '2022-04-26' AND hist.userid = 'DOMAIN\John.Smith')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading