Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formual for weight loss

Status
Not open for further replies.

FB1

Instructor
May 31, 2005
69
GB
Have data that is recorded several time each month.
need to be able to pull out month difference

A big thank you for everyones help
I know I can put them into a detail(as there can be 10-15 different entries each month), then group on date field monthly
but I need to be able to show the weight loss or gain from the month before
only need to look at pre entries

Ralph

Required
"Pre Date","Weigth","Change/Month",BMI
06/02/2012,"100.0 ","-0.2 loss",122
11/01/2012,"100.2 ","0.0 gain",123
16/12/2011,"100.2 ","0.2 gain",122
21/11/2011,"100.0 ","-0.2 loss",124
26/10/2011,"100.2 ","-0.2 loss",125
26/09/2011,"100.4 ","1.6 gain",132

the fields are called

oid
fk_oid (patients id)
didat (Date)
Prepost ( weather a pre rec or a post record)
diwt (weight)
BMI

 
hi if anyone needs to know how I did this
as follows

select
oid as recid,
fk_oid as patientid,
DIDAT as date,
prepost,
DIWT as weight,
DIBPS, DIBPD, DIGAIN, DIIW, DIHEIGHT,
sp_bmi(oid) as BMI
from p_anthropometry as pa1
where prepost = '200100' and pa1.fk_oid = {?ThisPat}
and DIDAT = (
select max(pa2.DIDAT)
from p_anthropometry as pa2
where prepost = '200100' and pa2.fk_oid ={?ThisPat}
and pa2.fk_oid = pa1.fk_oid
and DATE_SUB(pa2.didat,INTERVAL (DAY(pa2.didat)-1) DAY) =
DATE_SUB(pa1.didat,INTERVAL (DAY(pa1.didat)-1) DAY)
and DATE_SUB(pa2.didat,INTERVAL (DAY(pa2.didat)-1) DAY) >=
adddate(DATE_SUB(didat,INTERVAL (DAY(curdate())-1) DAY) , -7))
order by fk_oid, didat desc limit 7
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top