not getting the desired output

  • if object_id('tempdb..#tmpExample') is not null

    drop table #tmpExample

    create table #tmpExample

    (rowidtinyintidentity(1,1),

    col1_refidtinyint,

    col1_valvarchar(10),

    col2_valvarchar(10),

    col3_valvarchar(10),

    col4_valvarchar(10)

    )

    insert#tmpExample

    (col1_refid, col1_val, col2_val, col3_val, col4_val )

    select 1, 'A', 'B', 'C', 'D'

    union

    select 1, 'E', 'F', 'G', 'H'

    union

    select 1, '1-A', '2-F', '3-C', '4-H'

    union

    select 2, 'J', 'K', 'I', 'O'

    union

    select 2, '1-J', '1-K', '1-I', '1-O'

    union

    select 3, 'M', 'N', 'E', 'D'

    union

    select 3, 'E-3', 'F-4', 'G-5', 'H-5'

    union

    select 4, 'P', 'K', 'I', 'O'

    union

    select 4, '1-R', '1-P', '1-W', '1-O'

    union

    select 5, 'MW', 'NQ', 'EV', 'DS'

    select * from #tmpExample order by col3_val

    if object_id('tempdb..#tmpExample') is not null

    drop table #tmpExample

    Output Required

    ===================

    distinct col1_refid.

    but the criteria is i want to pass order by clause dynamically and i want the distinct col1_refid. in sorted order, whtever sort criteria i'll send.

    e.g

    select top 100 percent col1_refid

    from #tmpExample order by col1_val, col2_val

    Like this.....

    Col_refid

    ---------

    1

    2

    4

    3

    5

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

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