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

Subtract value in one record from another Expand / Collapse
Author
Message
Posted Tuesday, November 26, 2013 5:34 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, July 10, 2014 3:56 AM
Points: 36, Visits: 80
Hello,

I have a table of Sample Results. Each patient can have up to three records in this table. I differentiate them by using a variable called 'SampleType', which can be 1, 2 or 3. I also have a variable called 'HB' which holds a decimal value.

I want to subtract the HB value in SampleType = 1 from the HB value in SampleType = 3 for a particular patient. I can use a variable called 'SubjectNumber' to identify a patient.

Is there a way to perform this calculation?

Many thanks for any help.
Post #1517622
Posted Tuesday, November 26, 2013 5:51 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, May 9, 2014 11:34 AM
Points: 128, Visits: 489
Hard to say w/o your schema and sample data but would this work?

select (T1.HB-T2.HB) as CalcValue
from SampleResults T1
inner join SampleResults T2
on T1.SubjectNumber = T2.SubjectNumber
where T1.SampleType = 1
and T2.SampleType = 3

Mark



Post #1517628
Posted Tuesday, November 26, 2013 5:57 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, July 10, 2014 3:56 AM
Points: 36, Visits: 80
Mark Eckeard (11/26/2013)
Hard to say w/o your schema and sample data but would this work?

select (T1.HB-T2.HB) as CalcValue
from SampleResults T1
inner join SampleResults T2
on T1.SubjectNumber = T2.SubjectNumber
where T1.SampleType = 1
and T2.SampleType = 3

Mark


Thank you Mark. That worked perfectly!
Post #1517630
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse