Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Count Months (periods) on program Expand / Collapse
Author
Message
Posted Thursday, September 18, 2008 8:34 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, May 22, 2014 8:55 AM
Points: 25, Visits: 120
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
2006 January 1 on 1
2006 February 2 on 2
2006 March 3 on 3
2006 April 4 on 4
2006 May 5 off 1
2006 June 6 off 2
2006 July 7 off 3
2006 August 8 off 4
2006 Sep 9 off 5
2006 October 10 on 1

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
Post #571824
Posted Thursday, September 18, 2008 9:12 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: 2 days ago @ 9:35 AM
Points: 1,519, Visits: 4,075
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 :: Running Totals :: Tally Table :: Cross Tabs/Pivots :: String Concatenation
Post #571860
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse