I need help to exclude specific devices from SQL query

Shreyas Kale 61 Reputation points
2022-07-25T12:06:05.347+00:00

I am using SQL query which shows the result of 1st IN & Last Out entry of unique UserID for current day from our attendance system SQL database.
In this query, I want to exclude some devices like - Bike Barrier Enter & Flap Barrier Enter 2.

Can you please help me, how can I exclude these devices from below query.224355-screenshot-2022-07-25-173342.png

Developer technologies Transact-SQL
SQL Server Other
0 comments No comments
{count} votes

Accepted answer
  1. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2022-07-25T12:40:35.833+00:00

    Not sure if I'm missing something, but why not just extend the WHERE clause in the CTE with:

       AND InLoc NOT IN ('Bike Barrier Enter', 'Flap Barrier Enter 2')  
    

    As for the "Access Denied" error, it may be that your query text is somehow trapped by a spam filter (please don't ask why). But you could attach the query in a file. (But if my Answer helps you, I don't think there is a need to do this.)


3 additional answers

Sort by: Most helpful
  1. Olaf Helper 47,436 Reputation points
    2022-07-25T12:08:56.29+00:00

    That's to less on information and we can't "query images" to reproduce/test it.
    Please post table design as DDL, some sample data as DML statement and the expected result.


  2. Naomi Nosonovsky 8,431 Reputation points
    2022-07-25T14:03:21.937+00:00

    Try to put your second query into another cte and then you should be able to add filter to it as Erland suggested. I can see you cannot do this directly in your query based on how it's structured.

    0 comments No comments

  3. Bert Zhou-msft 3,436 Reputation points
    2022-07-26T01:59:13.993+00:00

    Hi,@Shreyas Kale

    Welcome to Microsoft T-SQL Q&A Forum!

    Have you tried adding a where filter after select --- FROM SourceTable like this:

    where NOT INLOC='Bike Barrier Enter' or NOT INLOC= 'Flap Barrier Enter 2'  
    

    Best regards,
    Bert Zhou


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.