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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate field by age range 1

Status
Not open for further replies.

NOLA

Technical User
Apr 14, 2003
18
0
0
US
I am trying to create a derive field that will sum employees with life insurance for a certain age range.

For example Total life insurance for age range 00 - 29 or 30-39 etc....

 
It depends on where you want to do the sum. If you want to use DataBase Grouping you could use this SQL Derived Field:

SUM(
CASE
WHEN (SYSDATE - BIRTHDATE) BETWEEN 0 AND 29 THEN 1
ELSE 0
END
)

Or if you want to do the math in the report as a Summary Field use this SQL Derived field:

CASE
WHEN (SYSDATE - BIRTHDATE) BETWEEN 0 AND 29 THEN 1
ELSE 0
END

This will return a 1 or 0 for each record. You would then click on the column of 1s and 0s and hit the sum button.

Specializing in ReportSmith Training and Consulting
 
Charles,
I am trying to get a headcount but when I use the logic listed below it only returns 5.

CASE
WHEN (SYSDATE - BIRTHDATE) BETWEEN 0 AND 29 THEN 1
WHEN (SYSDATE - BIRTHDATE) BETWEEN 30 AND 39 THEN 2
WHEN (SYSDATE - BIRTHDATE) BETWEEN 40 AND 49 THEN 3
WHEN (SYSDATE - BIRTHDATE) BETWEEN 50 AND 59 THEN 4
else 5
end


 
Charles,

I also tried the code listed below and still receiving only 5.

CASE
when trunc((SYSDATE - "PS_PERSONAL_DATA"."BIRTHDATE")) < 5 then 1
when trunc((SYSDATE - "PS_PERSONAL_DATA"."BIRTHDATE")) < 10 then 2
when trunc((SYSDATE - "PS_PERSONAL_DATA"."BIRTHDATE")) < 15 then 3
when trunc((SYSDATE - "PS_PERSONAL_DATA"."BIRTHDATE")) < 20 then 4
Else 5
end
 
trunc(SYSDATE - "PS_PERSONAL_DATA"."BIRTHDATE") returns a value in days. To get years divide by 365.

Try this:

CASE
when TRUNC((SYSDATE - "PS_PERSONAL_DATA"."BIRTHDATE") / 365) < 5 then 1
when TRUNC((SYSDATE - "PS_PERSONAL_DATA"."BIRTHDATE") / 365) < 10 then 2
when TRUNC((SYSDATE - "PS_PERSONAL_DATA"."BIRTHDATE") / 365) < 15 then 3
when TRUNC((SYSDATE - "PS_PERSONAL_DATA"."BIRTHDATE") / 365) < 20 then 4
Else 5
end



Specializing in ReportSmith Training and Consulting
 
Thanks Charles. It worked.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top