CAST Statement

Hi,

I have two fields "Action" & "Action Date" of "Detail_Trans" table.  I need to display three action time based on the different action.

I have created three different action formulas like below:

Formula 1:

If {Detail_Trans.ACTION} = 1 Then {Detail_Trans.ACTION_TIME}

Formula 2:

If {Detail_Trans.ACTION} = 2 Then {Detail_Trans.ACTION_TIME}

Formula 3:

If {Detail_Trans.ACTION} = 3 Then {Detail_Trans.ACTION_TIME}

But my report display duplicate records if it have more than action. I am wondering should I use CASE statement for this. Please advise.

Thanks,
rowfeiAsked:
Who is Participating?
 
James0628Connect With a Mentor Commented:
To clarify and correct a couple of things ...

 When mlmcc said to "put the formulas into the Trans_id group footer", I assume that he was referring to the formulas that he posted, not your old formulas.  If you put your old formulas in the transaction group footer, you'll only get a date for whichever Action happens to be in the last record in the group.  The idea is to use your old formulas to produce a date for each Action, and then, in the transaction group footer, display the highest date produced by each of those formulas for that transaction.

 I assume that the Action1Date, Action2Date and Action3Date in mlmcc's formulas should be replaced by your formula names.  He used Max, but that should be Maximum.  And he left out the closing } after Trans_Id.  Rewriting his 3 formulas with those corrections, and more generic terms, they would be:

Maximum ({@your old Action 1 formula}, {transaction group field})

Maximum ({@your old Action 2 formula}, {transaction group field})

Maximum ({@your old Action 3 formula}, {transaction group field})

 Replace the formula and field names with your actual names.


 James
1
 
mlmccCommented:
Duplicate records are generally caused by
1.  Actually having duplicate records in the data source
2.  Having incorrect joins in the data source

Does the report use multiple tables?

mlmcc
0
 
rowfeiAuthor Commented:
Hi mlmcc,

Yes, the report have multiple tables. I am link main table "Summarry_Trans" to "Detail_Trans" via trans_id.

"Summarry_Trans" table only contains one trans_id. But "Detail_Trans" contains duplicate trans_id because the same trans_id can have different "Action." Below is my report looks like now. I have tried to change left join & inner join, the report results are the same like below.

Trans_ID        Action 1 Date     Action 2 Date   Action 3 Date
123                     2/1/2016            1900/01/01       1900/01/01
123                     1900/01/01        3/3/2016           1900/01/01
123                     1900/01/01        1900/01/01         4/1/2016

Below is what I expect from the report:

Trans_ID        Action 1 Date     Action 2 Date   Action 3 Date
123                     2/1/2016             3/3/2016      4/1/2016

Thanks,
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
HuaMinChenSystem managerCommented:
Try to put
select distinct ..

Open in new window

on relevant SQL statement
0
 
rowfeiAuthor Commented:
It's built by Crystal Report. How can I add SQL? Thanks,
0
 
mlmccCommented:
You are going to need to use a SQL Command rather than the tables directly.

You command will  be something like

SELECT ST.Trans_id, AD1.Action1Date, AD2.Action2Date, AD3.Action3Date
FROM Summarry_Trans ST LEFT OUTER JOIN Detail_Trans AD1 ON ST.Trans_Id = AD1.Trans_Id AND AD1.Action1Date <> Date(1900,01,01)  LEFT OUTER JOIN Detail_Trans AD2 ON ST.Trans_Id = AD2.Trans_Id AND AD2.Action2Date <> Date(1900,01,01)  LEFT OUTER JOIN Detail_Trans AD3 ON ST.Trans_Id = AD3.Trans_Id AND AD3.Action3Date <> Date(1900,01,01)

mlmcc
0
 
rowfeiAuthor Commented:
Thanks, mlmcc. I have other 10 tables and 15 formulas already built in this report. Is there anyway I can modify the existing three formulas below to limit the duplicate?

Formula 1:

If {Detail_Trans.ACTION} = 1 Then {Detail_Trans.ACTION_TIME}

Formula 2:

If {Detail_Trans.ACTION} = 2 Then {Detail_Trans.ACTION_TIME}

Formula 3:

If {Detail_Trans.ACTION} = 3 Then {Detail_Trans.ACTION_TIME}
0
 
mlmccConnect With a Mentor Commented:
Will Action Dates 1, 2, and 3 always have a date other than 01-10-1900?
Will there only be 1 such date?

You could group on the Trans_id and put formulas in for the dates
Action Date 1
Max({Action1Date}, {Trans_Id)

Action Date 2
Max({Action2Date}, {Trans_Id)

Action Date 3
Max({Action3Date}, {Trans_Id)

mlmcc
0
 
rowfeiAuthor Commented:
Yes, Action Date always have a date other than 01-10-1900. It only have one date for each action.

I am still confusing about the grouping suggestion above.

Beside the existing three formulas below, I should create another three more for the grouping?

Formula 1:

If {Detail_Trans.ACTION} = 1 Then {Detail_Trans.ACTION_TIME}

Formula 2:

If {Detail_Trans.ACTION} = 2 Then {Detail_Trans.ACTION_TIME}

Formula 3:

If {Detail_Trans.ACTION} = 3 Then {Detail_Trans.ACTION_TIME}
0
 
mlmccConnect With a Mentor Commented:
Group on the Trans_id then put the formulas into the Trans_id group footer to display the data as you desire it.

Delete the dates from the details

mlmcc
0
All Courses

From novice to tech pro — start learning today.