# Sql formula

....... I cant get this formula to work. I hope you can help me without having the database to test with.

So I need to calculate the eGFR (Estimated glomular filtration rate) using CKD-EPI formula (I am use to the more simple formula of MDRD).

See below formula.....

GFR = 141 * min(Scr/ê,1)á * max(Scr/ê, 1)-1.209 * 0.993Age * 1.018 [if female] * 1.159 [if black]

Scr is serum creatinine (mg/dL), ê is 0.7 for females and 0.9 for males, á is -0.329 for females and -0.411 for males, min indicates the minimum of Scr/ê or 1, and max indicates the maximum of Scr/ê or 1.

This is my attempt (and it is not working)......

Male=16012, Female=17012, Raceb(black)=1 (if yes)

.........................................................................................................

141 * (number( gf_crf_sqlevaluate(keyid,"select min(lborres) from comp_lb where lbtest='Creatinine' and lbcat in(2,140012) and keyid='"+keyid+"'",1,1))/

( if( number(gf_crf_sqlevaluate(keyid,"select sex from comp_dm where comp_dm.usubjid='"+usubjid+"'",1,1))=17012, 0.7, 0.9))

)

^ if( number(gf_crf_sqlevaluate(keyid,"select sex from comp_dm where comp_dm.usubjid='"+usubjid+"'",1,1))=17012, -0.329, -0.411)

• ((number( gf_crf_sqlevaluate(keyid,"select max(lborres) from comp_lb where lbtest='Creatinine' and lbcat in(2,140012) and keyid='"+keyid+"'",1,1))/

( if( number(gf_crf_sqlevaluate(keyid,"select sex from comp_dm where comp_dm.usubjid='"+usubjid+"'",1,1))=17012, 0.7, 0.9))

)) ^ -1.209 *

• 0.993 ^ (number( gf_crf_sqlevaluate(keyid,"select agecalc from comp_dm where comp_dm.usubjid='"+usubjid+"'",1,1)) )

if( number(gf_crf_sqlevaluate(keyid,"select sex from comp_dm where comp_dm.usubjid='"+usubjid+"'",1,1))=17012, 1.018, 1)

if( number( gf_crf_sqlevaluate(keyid,"select raceb from comp_dm where comp_dm.usubjid='"+usubjid+"'",1,1))=1, 1.159, 1)

Can you provide ddl and sample data as well as expected results? Something like this with data and expected outcomes, It's confusing not knowing what you are dealing with

``````Create table #Temp (
SCR decimal(3,1),
a decimal(4,3) ,
e decimal(6,3),
Gender char(1),
Raceb tinyint

)``````