Looking for a way to exclude certain items from my query

2478 views sql-server

I currently have a Query I'm running daily and I'd like to exclude certain items from this Query that I've already identified as not wanting to see without adding another table to the database. Below is my attempt at this, which works with one TaskID but not multiple TaskIDs as I'm trying to do. I feel its also important to note that this list could grow into roughly 150 ID's but not necessarily over 200 if that makes a difference. Obviously the way I did it is not the best way. Can anyone recommend the best way to accomplish this?

Direct Question: What is the best way to exclude a large number of TaskID's from the below query without creating another table?

SELECT  TaskID,max(timeended) as 'Last Run' from  [moveitautomationagain].[dbo].taskruns
where TaskID <> 222300 OR TaskID <> 103439128
group by TaskID
having DATEDIFF(hour,max(timeended),sysdatetime()) > 24

answered question

1 Answer


For your query you need AND not OR. However I would use NOT IN i.e.

where TaskID not in (222300, 103439128)

posted this

Have an answer?


Please login first before posting an answer.