×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Calculate field by age range

Calculate field by age range

Calculate field by age range

(OP)
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....

RE: Calculate field by age range

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.

http://CharlesCook.com
Specializing in ReportSmith Training and Consulting

RE: Calculate field by age range

(OP)
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


RE: Calculate field by age range

(OP)
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

RE: Calculate field by age range

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

http://CharlesCook.com
Specializing in ReportSmith Training and Consulting

RE: Calculate field by age range

(OP)
Thanks Charles.  It worked.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close