• nutty (11/20/2013)


    Hi

    Apologies for not following the format. I will keep this in mind next time.

    My desired output is

    Parent_Count | Child_count

    2 7

    Thanks

    Mita

    something like this work?

    create table #Something

    (

    Line_no int,

    code varchar(5),

    AccountNo char(5)

    )

    insert #Something

    select 123, 'C12', 'Ac111' union all

    select 1222, 'C12', 'Ac111' union all

    select 1243, 'C12', 'Ac111' union all

    select 433, 'P1', 'Ac111' union all

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

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

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

    select 4322, 'P1', 'Ac222' union all

    select 4322, 'L1', 'Ac222'

    select SUM(case when left(code, 1) = 'P' then 1 end) as Parent, SUM(case when left(code, 1) in ('C', 'L') then 1 end) as Parent

    from #Something

    drop table #Something

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/