Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Date range in select statement
Message
From
04/12/2001 16:56:46
 
 
To
04/12/2001 16:08:49
John Deupree
Long Term Care Authority
Tulsa, Oklahoma, United States
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00589506
Message ID:
00589537
Views:
23
>I have a consumer status table that contains the consumer id, the consumer's status (active, inactive, etc.) and the begin date of the status (the end date is not included - it's assumed that the previous status ended the day the new status began). I would like to determine the date range (or # of days) that a consumer had a certain status. Is there any way to do this with a SQL statement?

Hi, John

Here's what I came up with. Sample data just to make sure I understood your question well:
create cursor costStatus (costumer_id n(4), status n(2), begindate d)

insert into costStatus (costumer_id, status, begindate) values (1,1,{^2001-11-1})
insert into costStatus (costumer_id, status, begindate) values (1,2,{^2001-11-3})
insert into costStatus (costumer_id, status, begindate) values (1,3,{^2001-11-6})
insert into costStatus (costumer_id, status, begindate) values (1,4,{^2001-11-10})
insert into costStatus (costumer_id, status, begindate) values (2,1,{^2001-11-1})
insert into costStatus (costumer_id, status, begindate) values (2,4,{^2001-11-25})

SELECT alfa.costumer_id, alfa.status, MIN(omega.begindate-alfa.begindate) AS days_in_status ;
FROM costStatus omega ;
INNER JOIN costStatus alfa ON omega.costumer_id = alfa.costumer_id ;
WHERE omega.begindate>alfa.begindate ;
GROUP BY 1, 2
bye
----------------------------------
António Tavares Lopes
Previous
Reply
Map
View

Click here to load this message in the networking platform