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

Selecting status from dates

Status
Not open for further replies.

Khawer

Programmer
Sep 13, 2004
23
CA
Hello,

I am on CR V.9 SQL. I have a quick question on how to create a formula based on status of an employee. Lets say

Employee | Status | Date
Tom Active 11/04/94
Tom Leave 12/04/00
Tom Term 03/05/01

Bill Active 07/01/99

John Active 04/01/98
John Leave 04/02/04

Bob Active 03/05/00
Bob Term 04/04/01
Bob Active 07/09/03
Bob Leave 09/29/05


Is there any way to grab the status of an employee based on the max date. This has to be done in one formula in the detail section. If someone can please point me the right direction, that be great. Thanks in advance
 
Formula placed in Report Header and supressed:

global datevar maxdate := #01/01/1980#;

________________________________________

Formula placed on detail line:

global datevar maxdate;
global stringvar status;

if {database.date} > maxdate then

( maxdate := {database.date};
status := {database.status};
_____________________________________
Formula placed on Group footer (Group by employee):
global stringvar status;
local stringvar show := status;
status := "";
maxdate := #01/01/1980#;
show

______________________________________

Cheers
paulmarr
 
Try this:

//@ShowStatus
if maximum({table.date},{table.employee}) = {table.date}
then {table.status}
else ""

Place the formula in the details section.


~Brian
 
If you only want to display the most recent record in the detail section, then you could either use group selection by going to report->selection formula->GROUP and entering:

{table.date} = maximum({table.date},{table.employee})

...or you could use "Add command" as your datasource (database->database expert->your datasource->add command and entering something like:

Select table.`employee`,table.`status`,table.`date`
From `table` table
Where table.`date` = (select max(A.`date`) from table A where A.`employee` = table.`employee`)

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top