Get the salary based on empno and month

  • i have table for each month which stores the employee's salary, i need SP which takes the input has empno and month with year has input, which should display the salary.

  • GA_SQL (10/3/2016)


    i have table for each month which stores the employee's salary, i need SP which takes the input has empno and month with year has input, which should display the salary.

    A separate table for every month? I think you should consider applying some normalisation before we move forward with a dynamic-SQL proc.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Ok,

  • GA_SQL (10/3/2016)


    Ok,

    ..Such that there is a single table containing salaries, with appropriate effective dates.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • But for each month i have 30 employees, how to maintain that in a single table

  • GA_SQL (10/3/2016)


    But for each month i have 30 employees, how to maintain that in a single table

    What's the problem? You could have 30 million employees and their salaries for several decades. That can be done easily in a single table.

    In a simplistic way of designing it, you just need: Date, EmployeeNo, Salary.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • GA_SQL (10/3/2016)


    But for each month i have 30 employees, how to maintain that in a single table

    First I'd just like to mention that vertically partitioning across multiple tables, when there are only 30 rows in each table, this has no practical value. If refactoring the data model isn't an option at this time, then consider creating a paritioned view to logically unionize all employee salaries into one logical table.

    For example:

    create view vEmployeeSalary as

    select * from EMPSAL201601

    union all

    select * from EMPSAL201602

    union all

    select * from EMPSAL201603

    ... etc

    ... etc

    GO

    Once done, it at least looks like one normalized table and you can query using straightforward SQL.

    For example:

    select * from vEmployeeSalary where EmployeeID = 999;

    "Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho

Viewing 7 posts - 1 through 6 (of 6 total)

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