SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Count Months (periods) on program


Count Months (periods) on program

Author
Message
No Idea
No Idea
SSC Rookie
SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)SSC Rookie (35 reputation)

Group: General Forum Members
Points: 35 Visits: 122
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
Garadin
Garadin
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2743 Visits: 4107
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search