T-SQL to SELECT rows where 2 columns in TBL_A do not exist in TBL_B

  • I have 2 tables: TBL_A and TBL_B each with the same 2 columns;

    ServerName nvarchar(50) and LoginName nvarchar(50)

    Looking for T-SQL to render:

    SELECT all rows that exist in TBL_A

    WHERE TBL_A ServerName NOT EXISTS in TBL_B AND TBL_A LoginName NOT EXISTS in TBL_B

    Any help is greatly appreciated. Thx

    BT
  • Can you refine the logic with some sample data / wanted output?

    select *
    from A
    where not exists (select * from b where a.server=b.server and a.login=b.login )

    or

    select *
    from A
    where not exists (select * from b where a.login=b.login )
    and not exists (select * from b where a.server=b.server )
    ....
  • thank you for your feedback and example Jo....

    so we have a list of SQL Logins, Windows Logins and A/D Groups that have been added as SYSADMIN to various SQL Servers stored in TBL_A as ServerName, LoginName <-- the LoginName is either a SQL Login, a Windows Login or an A/D Group name..

    we have a 2nd process which captures ALL LOGINS (either a SQL Login, a Windows Login or an A/D Group name) accessing a SQL Server and stores that ServerName and LoginName in TBL_B

    I'd like to identify all Users that are in TBL_A that have not accessed the Server (TBL_B)

    BT

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply