CUBE OR ROLLUP HERE WE USE? PLS HELP ME!!

  • Hello Friends,

    Please Help Me Out!!

    Note: Employee ID is Primary Key
    Department IDEmployee NameEmployee ID
    101MackA1001
    101KrishA1003
    101HarshA1004
    101MarryA1008
    103SusamA1016
    103MohanA1021
    103GayleA1033
    104KingA1000
    105PotterA1005
    105HussainA1006

    Here My Table And I want Output like below

    Department IDEmployee NameEmployee ID
    101MackA1001
    KrishA1003
    HarshA1004
    MarryA1008
    103SusamA1016
    MohanA1021
    GayleA1033
    104KingA1000
    105PotterA1005
    HussainA1006

    Can Anybody have solution for this?

    T I A

    Shashank


    Regards,

    Papillon

  • Something like:

    SELECT

      CASE WHEN [Employee ID] = (SELECT MIN([Employee ID]) FROM emp e

                                      WHERE e.[Department ID] = emp.[Department ID])

      THEN CAST([Department ID] AS varchar(10))

      ELSE '' 

      END AS [Department],

      [Employee Name], 

      [Employee ID]

    from emp

    ORDER BY [Department ID], [Employee ID]

    Important that you call the first field something other than [Department ID],

    so it can sort by the original department ID field. The first field gets cast to

    a string so you can send a blank rather than just a NULL if it was an integer.

  • Hello friends!!!!!

    The solution which Tony Webster has given that worked out!!!!

    Thanks Tony!!!!

    Shashank

     

     


    Regards,

    Papillon

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

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