• Hi Jeff

    Here is what I want:

    create table #Something

    (

    Line_no int,

    code varchar(5),

    AccountNo char(5)

    )

    insert #Something

    select 12311, 'P1c', 'Ac115' union all

    select 12311, 'L1', 'Ac115' union all

    select 123, 'C1', 'Ac115' union all

    select 1222, 'C1', 'Ac115' union all

    select 1243, 'C1', 'Ac115' union all

    select 433, 'P1a', 'Ac111' union all

    select 433, 'L1', 'Ac111' union all

    select 4331, 'C1', 'Ac111' union all

    select 543, 'C1', 'Ac222' union all

    select 544, 'C1', 'Ac222' union all

    select 4322, 'P1b', 'Ac222' union all

    select 4322, 'L1', 'Ac222' union all

    select 8766 'P1d' , 'Ab111' union all

    select 8767 'C1', 'Ab111' union all

    select 8789 'C1', ' Ab111' union all

    select 8766 'L1', ' Ab111'

    select * from #Something

    drop table #Something

    Desired output is:

    [Parent code] [Parent line Count] [Child line Count]

    P1c 1 3

    P1a 1 1

    P1b 1 2

    P1d 1 2