• KGJ-Dev (8/23/2014)


    Hi, Below is the TestData,

    With SalaryReport as (

    Select 1 as IdSalary,100 as IDMainCompany , 1000 as IDSubCompany ,200000 AS Salary, 20000 as Incentive, 500 as NoofEmployees,

    '2014-01-01' as SalaryDate union all

    Select 2 as IdSalary,100 as IDMainCompany , 1001 as IDSubCompany ,300000 AS Salary, 40000 as Incentive, 600 as NoofEmployees,

    '2014-01-01' as SalaryDate union all

    Select 3 as IdSalary,100 as IDMainCompany , 1002 as IDSubCompany ,400000 AS Salary, 40000 as Incentive, 1500 as NoofEmployees,

    '2014-01-01' as SalaryDate union all

    Select 4 as IdSalary,101 as IDMainCompany , 1003 as IDSubCompany ,30000 AS Salary, 2000 as Incentive, 100 as NoofEmployees,

    '2014-01-01' as SalaryDate union all

    Select 5 as IdSalary,102 as IDMainCompany , 1004 as IDSubCompany ,450000 AS Salary, 25000 as Incentive, 700 as NoofEmployees,

    '2014-01-01' as SalaryDate

    )

    Pareamter to be passed to query:

    Declare @ IDMainCompany int = 100, @Process_Date datetime = '2014-01-01'

    Expected output:

    Am very confused about how to use group by and bring the expected output as like above. any sample query please

    This looks like something that should be done in the front end, SSRS or Excel; not in the SQL itself.