Count Months (periods) on program

  • We have clients that are on a program for a few months, then off, then back on the program again. I need to find out how many months they are on the program and then how long they stay on or stay off (spells on or spells off)

    For example, if January 2006 is period 1, February is period 2 and until September 2008 is period 33 then if I have a client ID, how many periods is the client on the program and if they are off how many months and for how long.

    Client 1 on the program Jan 2006 (period 1) through April 2006 (period 4), off the program from May 2006 (period 5) to September 2006 (period 9) but is back on in October 2006 (period 10).

    So the client is on for periods 1-4 which makes that a spell count of 4, off for 5 spells then back on.

    Year Month Period On/off Spells

    2006January1on1

    2006February2on2

    2006March3on3

    2006April4on4

    2006May5off1

    2006June6off2

    2006July7off3

    2006August8off4

    2006Sep 9off5

    2006October10on1

    Since there are thousands of clients, is there a way to get this to work in T-SQL 2000? I need to know the period and spells for each client.

    Thanks

  • Is the data you supplied an actual example of your how data table is structured, or is that just to help explain what you need? If the latter, how is the data in your tables structured?

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. 😉

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]

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

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