Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 7,2000
»
T-SQL
»
Count Months (periods) on program
Count Months (periods) on program
Rate Topic
Display Mode
Topic Options
Author
Message
No Idea
No Idea
Posted Thursday, September 18, 2008 8:34 AM
Grasshopper
Group: General Forum Members
Last Login: Wednesday, September 28, 2011 6:47 AM
Points: 23,
Visits: 107
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
Garadin
Garadin
Posted Thursday, September 18, 2008 9:12 AM
SSCommitted
Group: General Forum Members
Last Login: Wednesday, November 07, 2012 4:08 PM
Points: 1,525,
Visits: 4,047
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 »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.