Decrementing date logic in a loop

  • Hello,

    I need to calculate retro worked days. I have built a program to generate the worked days of a present pay period for a particular work contract. Now HR wants me to generate worked days that are prior to this present pay period. This is termed their Late Contract. So through sql I found the retro pay period for the particular work contract. So using DateDiff I know that I can find the days between the Begin Pay Date and the Retro Pay Begin Date. So for example

    If I worked Mon and Wed for the the current pay period, I will need to go back 48 days to calculate the missed pay days for all the scheduled Mon and Wed. I know that I can do this programmatically as a sql object and a loop in peoplecode for oracle, I was wondering if there is a way to do this with an Insert Statement/Select using just sql.

    Thanks,

    Nigluc.

  • nigluc (5/30/2012)


    Hello,

    I need to calculate retro worked days. I have built a program to generate the worked days of a present pay period for a particular work contract. Now HR wants me to generate worked days that are prior to this present pay period. This is termed their Late Contract. So through sql I found the retro pay period for the particular work contract. So using DateDiff I know that I can find the days between the Begin Pay Date and the Retro Pay Begin Date. So for example

    If I worked Mon and Wed for the the current pay period, I will need to go back 48 days to calculate the missed pay days for all the scheduled Mon and Wed. I know that I can do this programmatically as a sql object and a loop in peoplecode for oracle, I was wondering if there is a way to do this with an Insert Statement/Select using just sql.

    Thanks,

    Nigluc.

    Yes you can do this and you certainly don't need a loop. It sounds like you need a tally or numbers table. Take a look at Jeff Moden's article about that here. http://www.sqlservercentral.com/articles/T-SQL/62867/%5B/url%5D

    _______________________________________________________________

    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/

  • Thank you,

    I really appreciate the input and I will use it in my solution to this issue.

    Nigluc:-)

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

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