Filter Data

  • EmpID    ID      NO    Name

      1        123    111    George

      1        NULL   111   George

      2        456     222   George

      2        475     222   Raj

      2        NULL   222    Raj

      3        NULL   333   Thomas

    I want only those records where the Name repeats more than once and EmpID is NULL.

    Desired Output

    EmpID    ID      NO    Name

      1        NULL   111   George

      2        NULL   222    Raj

    Thanks

     

     

     

  • declare @test-2 table (empid int, id int, no int, name varchar(100))

    insert @test

    select 1, 123, 111, 'George' union all

    select 1, NULL, 111, 'George' union all

    select 2, 456, 222, 'George' union all

    select 2, 475, 222, 'Raj' union all

    select 2, NULL, 222, 'Raj' union all

    select 3, NULL, 333, 'Thomas'

    SELECT DISTINCT t.*

    FROM  @Test t

    INNER JOIN (

       SELECT  EmpID

       FROM  @Test

       GROUP BY EmpID

       HAVING  COUNT(*) > 1

     &nbsp z ON z.EmpID = t.EmpID

    WHERE  t.ID IS NULL


    N 56°04'39.16"
    E 12°55'05.25"

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

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